jhorsman
5/6/2015 - 9:38 AM

Pretty print a JSON string in PowerShell

Pretty print a JSON string in PowerShell

$json = @"
{"RevisionDate":"2015-03-03T13:32:23.577","Filename":"index","LastPublishedDate":"0001-01-01T00:00:00","PageTemplate":{"FileExtension":"html","RevisionDate":"2015-03-03T13:31:29.133","MetadataFields":{"includes":{"Name":"includes","Values":["system/include/header","system/include/footer","system/include/content-tools","system/include/left-navigation"],"FieldType":0},"view":{"Name":"view","Values":["GeneralPage"],"FieldType":0}},"Folder":{"PublicationId":"tcm:0-4-1","Id":"tcm:4-23-2","Title":"Templates"},"Publication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"OwningPublication":{"Id":"tcm:0-3-1","Title":"100 Master"},"Id":"tcm:4-208-128","Title":"Content Page"},"MetadataFields":{},"ComponentPresentations":[{"Component":{"LastPublishedDate":"0001-01-01T00:00:00","RevisionDate":"2015-03-03T13:32:04.423","Schema":{"Folder":{"PublicationId":"tcm:0-4-1","Id":"tcm:4-24-2","Title":"Schemas"},"RootElementName":"Article","Publication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"Id":"tcm:4-109-8","Title":"Article"},"Fields":{"headline":{"Name":"headline","Values":["Company Information"],"FieldType":0,"XPath":"tcm:Content/custom:Article/custom:headline"},"articleBody":{"Name":"articleBody","EmbeddedValues":[{"subheading":{"Name":"subheading","Values":["Vision and Mission"],"FieldType":0,"XPath":"tcm:Content/custom:Article/custom:articleBody[1]/custom:subheading"},"content":{"Name":"content","Values":["<p>Lorem ipsum dolor sit amet, <a xlink:href=\"tcm:4-251\" title=\"Contact Tab Content\" xlink:title=\"Contact Tab Content\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">consectetur adipiscing</a> elit. Sed diam purus, tincidunt volutpat mauris a, lacinia luctus velit. Nam dui purus, pretium sit amet sagittis vel, lobortis eu est. Morbi sagittis pellentesque facilisis. Phasellus accumsan, ante non aliquet dignissim, turpis diam placerat odio, sit amet rutrum tortor magna nec diam. Nulla adipiscing in quam sit amet faucibus. Nunc congue velit ac leo sodales, quis mattis massa tincidunt.</p><p>Nullam fringilla volutpat arcu, vitae ultricies ante lobortis ac. Quisque elementum nunc congue, luctus mi quis, vestibulum lacus. Vestibulum nec dui nibh. Mauris consectetur risus dui, eget ultricies sapien imperdiet vitae. Praesent metus tortor, adipiscing sed feugiat vitae, accumsan vitae ipsum. Morbi sodales, sapien nec vehicula blandit, turpis nisl mattis metus, vel ultrices eros magna sit amet odio.</p>"],"FieldType":2,"XPath":"tcm:Content/custom:Article/custom:articleBody[1]/custom:content"},"media":{"Name":"media","Values":["tcm:4-252"],"LinkedComponentValues":[{"LastPublishedDate":"0001-01-01T00:00:00","RevisionDate":"2015-03-03T13:32:02.423","Schema":{"Folder":{"PublicationId":"tcm:0-4-1","Id":"tcm:4-24-2","Title":"Schemas"},"RootElementName":"undefined","Publication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"Id":"tcm:4-133-8","Title":"YouTube Video"},"Fields":{},"MetadataFields":{"youTubeId":{"Name":"youTubeId","Values":["2YBtspm8j8M"],"FieldType":0,"XPath":"tcm:Metadata/custom:Metadata/custom:youTubeId"},"headline":{"Name":"headline","Values":["Company News"],"FieldType":0,"XPath":"tcm:Metadata/custom:Metadata/custom:headline"}},"ComponentType":0,"Multimedia":{"Url":"/media/company-news-placeholder_tcm4-252.png","MimeType":"image/png","FileName":"company-news-placeholder.png","FileExtension":"png","Size":674712,"Width":0,"Height":0},"Folder":{"PublicationId":"tcm:0-4-1","Id":"tcm:4-68-2","Title":"Video"},"Categories":[],"Version":1,"Publication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"OwningPublication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"Id":"tcm:4-252","Title":"Company News Media Manager Video"}],"FieldType":5,"XPath":"tcm:Content/custom:Article/custom:articleBody[1]/custom:media"},"caption":{"Name":"caption","Values":["Phasellus accumsan, ante non aliquet dignissim"],"FieldType":0,"XPath":"tcm:Content/custom:Article/custom:articleBody[1]/custom:caption"}},{"subheading":{"Name":"subheading","Values":["History"],"FieldType":0,"XPath":"tcm:Content/custom:Article/custom:articleBody[2]/custom:subheading"},"content":{"Name":"content","Values":["<p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Ut porttitor nisi nunc. Aenean commodo arcu vehicula enim tincidunt sodales. Proin tristique mi id nisi dignissim, eget congue purus blandit. Vestibulum dignissim sollicitudin sapien, eget pellentesque dui pellentesque sodales. In hac habitasse platea dictumst. Cras placerat at libero at porta. Vivamus eget magna eros:</p><ul><li>Integer scelerisque ipsum quis sodales congue.</li><li>Nunc sollicitudin orci sit amet risus dapibus, a vehicula ipsum ultrices.</li><li>Sed ut felis at sem blandit auctor.</li></ul>"],"FieldType":2,"XPath":"tcm:Content/custom:Article/custom:articleBody[2]/custom:content"}},{"subheading":{"Name":"subheading","Values":["Leadership"],"FieldType":0,"XPath":"tcm:Content/custom:Article/custom:articleBody[3]/custom:subheading"},"content":{"Name":"content","Values":["<p>Maecenas quis mi ipsum. Morbi dapibus diam fermentum urna porta, a rutrum quam blandit. Phasellus fermentum vitae nisl non lacinia. Nulla in nulla sit amet eros suscipit consectetur a quis orci. Mauris id turpis vitae magna ultricies accumsan. Nunc velit quam, congue vel magna at, mattis dapibus orci.</p><ul><li>Nulla varius nibh ut massa ornare, rhoncus dictum quam mollis.</li><li>Suspendisse placerat nulla sed feugiat eleifend.</li><li>Vestibulum molestie mi sit amet porttitor lacinia.</li><li>Integer scelerisque ipsum quis sodales congue.</li><li>Nunc sollicitudin orci sit amet risus dapibus, a vehicula ipsum ultrices.</li><li>Sed ut felis at sem blandit auctor.</li></ul>"],"FieldType":2,"XPath":"tcm:Content/custom:Article/custom:articleBody[3]/custom:content"},"media":{"Name":"media","Values":["tcm:4-253"],"LinkedComponentValues":[{"LastPublishedDate":"0001-01-01T00:00:00","RevisionDate":"2015-03-03T13:32:03.79","Schema":{"Folder":{"PublicationId":"tcm:0-4-1","Id":"tcm:4-24-2","Title":"Schemas"},"RootElementName":"undefined","Publication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"Id":"tcm:4-100-8","Title":"Image"},"Fields":{},"MetadataFields":{},"ComponentType":0,"Multimedia":{"Url":"/media/planes_tcm4-253.jpg","MimeType":"image/jpeg","FileName":"planes.jpg","FileExtension":"jpg","Size":641261,"Width":0,"Height":0},"Folder":{"PublicationId":"tcm:0-4-1","Id":"tcm:4-55-2","Title":"Large"},"Categories":[],"Version":1,"Publication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"OwningPublication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"Id":"tcm:4-253","Title":"planes"}],"FieldType":5,"XPath":"tcm:Content/custom:Article/custom:articleBody[3]/custom:media"},"caption":{"Name":"caption","Values":["Maecenas quis sem sit amet risus pellentesque laoreet eget at quam"],"FieldType":0,"XPath":"tcm:Content/custom:Article/custom:articleBody[3]/custom:caption"}}],"EmbeddedSchema":{"Folder":{"PublicationId":"tcm:0-4-1","Id":"tcm:4-25-2","Title":"Embedded"},"RootElementName":"Paragraph","Publication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"Id":"tcm:4-108-8","Title":"Paragraph"},"FieldType":4,"XPath":"tcm:Content/custom:Article/custom:articleBody"}},"MetadataFields":{"standardMeta":{"Name":"standardMeta","EmbeddedValues":[{"description":{"Name":"description","Values":["In sodales elementum lorem, at sollicitudin quam placerat in. Suspendisse vitae purus eu dolor mattis mollis. Nulla sit amet orci ac arcu suscipit commodo ut in tellus. Praesent ultrices lacus massa, at consequat augue consectetur a."],"FieldType":1,"XPath":"tcm:Metadata/custom:Metadata/custom:standardMeta[1]/custom:description"},"introText":{"Name":"introText","Values":["In sodales elementum lorem, at sollicitudin quam placerat in. Suspendisse vitae purus eu dolor mattis mollis."],"FieldType":0,"XPath":"tcm:Metadata/custom:Metadata/custom:standardMeta[1]/custom:introText"}}],"EmbeddedSchema":{"Folder":{"PublicationId":"tcm:0-4-1","Id":"tcm:4-25-2","Title":"Embedded"},"RootElementName":"StandardMetadata","Publication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"Id":"tcm:4-80-8","Title":"Standard Metadata"},"FieldType":4,"XPath":"tcm:Metadata/custom:Metadata/custom:standardMeta"}},"ComponentType":1,"Folder":{"PublicationId":"tcm:0-4-1","Id":"tcm:4-57-2","Title":"About"},"Categories":[],"Version":1,"Publication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"OwningPublication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"Id":"tcm:4-254","Title":"Company Information"},"ComponentTemplate":{"OutputFormat":"HTML Fragment","RevisionDate":"2015-03-03T13:31:15.33","MetadataFields":{"view":{"Name":"view","Values":["Article"],"FieldType":0}},"Folder":{"PublicationId":"tcm:0-4-1","Id":"tcm:4-23-2","Title":"Templates"},"Publication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"OwningPublication":{"Id":"tcm:0-3-1","Title":"100 Master"},"Id":"tcm:4-111-32","Title":"Article"},"IsDynamic":false,"OrderOnPage":0}],"StructureGroup":{"PublicationId":"tcm:0-4-1","Id":"tcm:4-56-4","Title":"About"},"Categories":[],"Version":1,"Publication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"OwningPublication":{"Id":"tcm:0-4-1","Title":"400 Example Site"},"Id":"tcm:4-294-64","Title":"000 Company Information"}
"@
$json | ConvertFrom-Json | ConvertTo-Json