powershell “ConvertTo-Json” has messed json format output
1) $Getjsonfilecontent = Get-Content "C:ScriptsCreateADF-DatasetsBUSI_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')]"
}
json powershell arm-template
add a comment |
1) $Getjsonfilecontent = Get-Content "C:ScriptsCreateADF-DatasetsBUSI_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')]"
}
json powershell arm-template
PowerShell evaluates double quoted strings, you should use single quote (literal) strings for the JSON values (and names).
– iRon
Nov 13 '18 at 19:19
add a comment |
1) $Getjsonfilecontent = Get-Content "C:ScriptsCreateADF-DatasetsBUSI_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')]"
}
json powershell arm-template
1) $Getjsonfilecontent = Get-Content "C:ScriptsCreateADF-DatasetsBUSI_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')]"
}
json powershell arm-template
json powershell arm-template
edited Nov 13 '18 at 18:56
Ram
asked Nov 13 '18 at 18:26
RamRam
206
206
PowerShell evaluates double quoted strings, you should use single quote (literal) strings for the JSON values (and names).
– iRon
Nov 13 '18 at 19:19
add a comment |
PowerShell evaluates double quoted strings, you should use single quote (literal) strings for the JSON values (and names).
– iRon
Nov 13 '18 at 19:19
PowerShell evaluates double quoted strings, you should use single quote (literal) strings for the JSON values (and names).
– iRon
Nov 13 '18 at 19:19
PowerShell evaluates double quoted strings, you should use single quote (literal) strings for the JSON values (and names).
– iRon
Nov 13 '18 at 19:19
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287346%2fpowershell-convertto-json-has-messed-json-format-output%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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
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
answered Nov 13 '18 at 19:17
RamRam
206
206
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287346%2fpowershell-convertto-json-has-messed-json-format-output%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
PowerShell evaluates double quoted strings, you should use single quote (literal) strings for the JSON values (and names).
– iRon
Nov 13 '18 at 19:19