Solved

Parse JSON config file in Powershell V3

Posted on 2013-05-10
2
3,176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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…

739 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