I'm trying to parse a json file and then parse it into a string. It seems that when I'm parsing in the way that I'm used to, an additional newline is being put into my data. In the examples below, my ConvertFrom-Json call does not include any empty members, but it appears as soon as I start processing the object it produces.
lints.json:
{
"lints": [
"needless_return",
"module-inception",
"many_single_char_names",
"implicit-hasher"
]
}
Get-Content ./lints.json | ConvertFrom-Json | % lints
needless_return
module-inception
many_single_char_names
implicit-hasher
needless_return
module-inception
many_single_char_names
implicit-hasher
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Darwin 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
I cannot reproduce this behavior with the sample input string - are you sure it is representative?
Does the following also reproduce your symptom?
@'
{
"lints": [
"needless_return",
"module-inception",
"many_single_char_names",
"implicit-hasher"
]
}
'@ | ConvertFrom-Json | % lints
@mklement0 Do you try on MacOS too?
The sample code appears to work just fine on MacOS (Catalina) for me. 馃槙
Thanks for confirming, @vexx32. @iSazonov, yes, I tried on macOS too (it's usually where I try first).
I guess the file contains broken newlnes.
More information might come from:
Format-Hex -Path ./lints.json