PowerShell: ConvertFrom-Json

I want to express a simple file format spec in Json format, and then ingest it into a PowerShell object.

The spec content:

And then various views in PowerShell

22 $specAsJson = Get-Content -Raw .\FileSpec.json
23 $spec = $specAsJson | ConvertFrom-Json
24 $spec
25 $spec.FriendsSpec
26 $spec.FriendsSpec.columnSet
27 $spec.FriendsSpec.columnSet.column1
28 $specAsJson.GetType()
29 $spec.GetType()

In fact on reflection those are the rules, the schema effectively… cept in Json I believe we don’t like schemas. So the spec for the Friends spec I meant… let’s call it RealFriends as I don’t intend going back:


(Note the typo ref ReaDFriends). This is more like it. With the added plus that as a first class object, we can do stuff like Count. Spec is

$specAsJson = Get-Content -Raw .\ReadFriendsSpec.json
$specAsJson
Get-History
$spec = $specAsJson | ConvertFrom-Json
$spec
$spec.FriendsSpec
$spec.FriendsSpec.Fields
$spec.FriendsSpec.Fields.Count

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s