Solved

Parse JSON config file in Powershell V3

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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
This article discusses how to implement server side field validation and display customized error messages to the client.
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)
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

696 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