1

1) $Getjsonfilecontent = Get-Content "C:\Scripts\CreateADF-Datasets\BUSI_RULE_BUILD_LOCATION_CODES_Source_Def.json" -Raw | ConvertFrom-Json

2) Append some key pair values to the json file

3) $Getjsonfilecontent | ConvertTo-Json -Depth 100 | % { [System.Text.RegularExpressions.Regex]::Unescape($_) } | set-content $Updatedleafjsonpath (Updatedleafjsonpath is a copy of base file 'Getjsonfilecontent')

when i do this, am seeing some format is messed from "$Updatedleafjsonpath" as shown below. All of the "\" are missing and "\n" is also messed in my output. Note: There is another section in same json file that is udpated with key pair values as part of step2, but this sections is not udpated and should remain as is before and after conversion. Any help on this is really appreciated.

Input: same output is expected.
 "typeProperties": {
                "format": {
                    "type": "TextFormat",
                    "columnDelimiter": "|",
                    "rowDelimiter": "\n",
                    "quoteChar": "\"",
                    "nullValue": "\"\"",
                    "encodingName": null,
                    "treatEmptyAsNull": true,
                    "skipLineCount": 0,
                    "firstRowAsHeader": false
                },
                "fileName": "[parameters('Veh_Obj_properties_typeProperties_fileName')]",
                "folderPath": "[parameters('Veh_Obj_properties_typeProperties_folderPath')]"
            }
                                             }

What i got after conversion:

"typeProperties":  {
                                                                "format":  {
                                                                               "type":  "TextFormat",
                                                                               "columnDelimiter":  "|",
                                                                               "rowDelimiter":  "
",
                                                                               "quoteChar":  """,
                                                                               "nullValue":  """",
                                                                               "encodingName":  null,
                                                                               "treatEmptyAsNull":  true,
                                                                               "skipLineCount":  0,
                                                                               "firstRowAsHeader":  false
                                                                           },
                                                                "fileName":  "[parameters('Veh_Obj_properties_typeProperties_fileName')]",
                                                                "folderPath":  "[parameters('Veh_Obj_properties_typeProperties_folderPath')]"
                                                            }
1
  • PowerShell evaluates double quoted strings, you should use single quote (literal) strings for the JSON values (and names). Commented Nov 13, 2018 at 19:19

1 Answer 1

1
never mind, got the answer.. added some more lines to code to make it work
$Getjsonfilecontent | ConvertTo-Json -Depth 100 | Out-File $Updatedleafjsonpath -Force
     # Remove unwanted Pattern
    $ReplacePatterns = @{
    "\\u003c" = "<"
    "\\u003e" = ">"
    "\\u0027" = "'"
    }
    $InputJson = Get-Content -Path $Getjsonfilecontent | Out-String
    foreach ($Pattern in $ReplacePatterns.GetEnumerator())
    {
        $InputJson = $InputJson -replace $Pattern.Key, $Pattern.Value
    }
    $InputJson | Out-File -FilePath $Updatedleafjsonpath
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.