Convertfrom-Json why are you not working
by Eric at 2012-09-13 22:33:32
I have exported an nicely formatted json document from splunk and I am just trying to run it into convertfrom-json.
$js = get-content .\test.json
$js | CovertFrom-Json
NotSpecified: (:) [ConvertFrom-Json], ArgumentException
I checked the json format and the output looks clean (no missing brackets or squiglies). From my understanding I can pipe the stream to this commandlet so what gives? Since it is new there is not much on the googs
by poshoholic at 2012-09-14 05:16:47
I haven't used this cmdlet much either other than a few simple examples. You might want to try the following troubleshooting steps though, to see if it helps identify what the problem is:
1. Copy your JSON file contents to this URL: http://jsonlint.com/. It seems to do JSON validating, which may identify some problem you're not seeing.
2. Convert something to JSON format using ConvertTo-JSON. For example, you could invoke this:
Get-Service wuauserv | ConvertTo-JSON
3. Compare the JSON format you get from ConvertTo-JSON with the file you're working with in ConvertFrom-JSON and see if you can identify any key differences.
4. Make a copy of your file and prune back the contents a bit, see if you can then convert it from JSON into a PSObject. If that works, repeat that test but pruning back less. See if you can first (a) get it working and then (b) identify what is causing it not to work.
This makes me think there should be a Test-JSON cmdlet that would do what jsonlint.com does.
by Eric at 2012-09-14 08:40:36
just popped the json into jslint.com and it came back "JSON: good."
I have done some more testing and basically stripped out all the carriage returns and white spaces and it ran successfully. I have a few other observations that I will update this thread with after I make sense of what I just did.
Bottom line it looks like convertfrom-json does not like json formatting. it looks like it needs to be a one line input of json data to work.
You must be logged in to reply to this topic.