Solved

Parse JSON config file in Powershell V3

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
A brief introduction to what I consider to be the best editor for 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…

770 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