Solved

Parse JSON config file in Powershell V3

Posted on 2013-05-10
2
2,916 Views
Last Modified: 2013-09-26
I have configuration file create in JSON structure that I need to parse in Powershell so that I can access the varies objects, array items, and so on.

Here is the script I am running

$FileName = "C:\DeployJsonConf.json"
$json = (Get-Content $FileName) | ConvertFrom-Json


And I am getting returned the following error so I am unable to try figuring out how to access the objects and so on inside the JSON.


ConvertFrom-Json : Invalid object passed in, ':' or '}' expected. (1): {
At C:\Users\testuser\AppData\Local\Temp\98f5dce2-83ec-4cd5-b2a6-82dcc618940b.ps1:7 char:35
+ $json = (Get-Content $FileName) | ConvertFrom-Json
+                                   ~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand



Any help would be appreciated.
0
Comment
Question by:sekoon
2 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39155621
test your config file here : http://jsonlint.com/
0
 
LVL 40

Accepted Solution

by:
Subsun earned 400 total points
ID: 39156974
Try...
$FileName = "C:\DeployJsonConf.json"
$json = Get-Content $FileName | Out-String | ConvertFrom-Json

Open in new window

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This article will help you understand what HashTables are and how to use them in PowerShell.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now