CURRENT STATUS: The forums you are now looking at are CLOSED. Visit the new forums.


Convertfrom-Json why are you not working

Creating PowerShell extensions in Visual Studio? Post here! Monitored by MVP Doug Finke.
Forum rules
1. Use the CODE or POWERSHELL buttons to format code and commands.
2. Avoid the use of obscure and punctuation aliases (like ? and %).
3. Don't apologize for being a "noob." We don't mind.
4. If we help you solve your question, please click the green SOLVED checkmark.

More forums tips & etiquette

Convertfrom-Json why are you not working

Postby Eric » Fri Sep 14, 2012 6:33 am

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

results in

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
User avatar
Eric
 
Posts: 15
Joined: Fri Aug 17, 2012 3:16 pm
Location: lake tahoe

Re: Convertfrom-Json why are you not working

Postby poshoholic » Fri Sep 14, 2012 1:16 pm

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.
Kirk Munro
Poshoholic, Microsoft MVP, Independent Consultant
Blog | Twitter | LinkedIn | Facebook

Need a PowerShell SME for a project at work? Contact me!
User avatar
poshoholic
MVP
MVP
 
Posts: 452
Joined: Sun Aug 12, 2012 7:10 pm
Location: Ottawa, Canada

Re: Convertfrom-Json why are you not working

Postby Eric » Fri Sep 14, 2012 4:40 pm

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.
User avatar
Eric
 
Posts: 15
Joined: Fri Aug 17, 2012 3:16 pm
Location: lake tahoe


Return to PowerShell for Developers

Who is online

Users browsing this forum: No registered users and 1 guest