Solved

Parse JSON config file in Powershell V3

Posted on 2013-05-10
2
2,959 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

895 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

17 Experts available now in Live!

Get 1:1 Help Now