Home > database >  Powershell - Cannot parse JSON - Get NotSpecified error
Powershell - Cannot parse JSON - Get NotSpecified error

Time:12-07

Code used to try parsing file

$myJson = Get-Content cleantest2.json -Raw | ConvertFrom-Json

Get below error when trying to parse JSON file.

$myJson = Get-Content cleantest2.json -Raw | ConvertFrom-Json
                                               ~~~~~~~~~~~~~~~~
      CategoryInfo          : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
      FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

EDIT: As noted, the above error was truncated because it was too long. Here is the full error.

ConvertFrom-Json : Invalid object passed in, ':' or '}' expected. (2): {"id":0,"resourcePackage
s":[{"resourcePackage":{"name":"SharedResources","type":2,"i
tems":[{"type":202,"path":"BaseThemes/CY18SU07.json","name"
:"CY18SU07"}],"disabled":false}}],"sections":[{"id":0,"name"
:"ReportSection","displayName":"Page 1","filters":"[]","ord
inal":0,"visualContainers":[{"x":10,"y":0,"z":1,"width":280,
"height":280,"config":"{\"name\":\"5a0b8ef6c97162087ff7\",\
"layouts\":[{\"id\":0,\"position\":{\"x\":10,\"y\":0,\"width
\":280,\"height\":280,\"z\":1}}],\"singleVisual\":{\"visual
Type\":\"tableEx\",\"projections\":{\"Values\":[{\"queryRef\
":\"servers_and_applications.App Name\"},{\"queryRef\":\"se
rvers_and_applications.Cust_Nme\"},{\"queryRef\":\"servers_a
nd_applications.MU_ID\"}]},\"prototypeQuery\":{\"Version\":
2,\"From\":[{\"Name\":\"s\",\"Entity\":\"servers_and_applica
tions\"}],\"Select\":[{\"Column\":{\"Expression\":{\"Source
Ref\":{\"Source\":\"s\"}},\"Property\":\"App
Name\"},\"Name\":\"servers_and_applications.App Name\"},{\"
Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},
\"Property\":\"Cust_Nme\"},\"Name\":\"servers_and_applicati
ons.Cust_Nme\"},{\"Column\":{\"Expression\":{\"SourceRef\":{
\"Source\":\"s\"}},\"Property\":\"MU_ID\"},\"Name\":\"serve
rs_and_applications.MU_ID\"}]},\"drillFilterOtherVisuals\":t
rue}}","filters":"[]","query":"{\"Commands\":[{\"SemanticQu
eryDataShapeCommand\":{\"Query\":{\"Version\":2,\"From\":[{\
"Name\":\"s\",\"Entity\":\"servers_and_applications\"}],\"S
elect\":[{\"Column\":{\"Expression\":{\"SourceRef\":{\"Sourc
e\":\"s\"}},\"Property\":\"App
Name\"},\"Name\":\"servers_and_applications.App Name\"},{\"
Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},
\"Property\":\"Cust_Nme\"},\"Name\":\"servers_and_applicati
ons.Cust_Nme\"},{\"Column\":{\"Expression\":{\"SourceRef\":{
\"Source\":\"s\"}},\"Property\":\"MU_ID\"},\"Name\":\"serve
rs_and_applications.MU_ID\"}]},\"Binding\":{\"Primary\":{\"G
roupings\":[{\"Projections\":[0,1,2],\"Subtotal\":1}]},\"Da
taReduction\":{\"DataVolume\":3,\"Primary\":{\"Window\":{\"C
ount\":500}}},\"Version\":1}}}]}","dataTransforms":"{\"proj
ectionOrdering\":{\"Values\":[0,1,2]},\"queryMetadata\":{\"S
elect\":[{\"Restatement\":\"App
Name\",\"Name\":\"servers_and_applications.App Name\",\"Typ
e\":2048},{\"Restatement\":\"Cust_Nme\",\"Name\":\"servers_a
nd_applications.Cust_Nme\",\"Type\":2048},{\"Restatement\":
\"MU_ID\",\"Name\":\"servers_and_applications.MU_ID\",\"Type
\":2048}]},\"visualElements\":[{\"DataRoles\":[{\"Name\":\"
Values\",\"Projection\":0,\"isActive\":false},{\"Name\":\"Va
lues\",\"Projection\":1,\"isActive\":false},{\"Name\":\"Val
ues\",\"Projection\":2,\"isActive\":false}]}],\"selects\":[{
\"displayName\":\"App
Name\",\"queryName\":\"servers_and_applications.App Name\",
\"roles\":{\"Values\":true},\"type\":{\"category\":null,\"un
derlyingType\":1},\"expr\":{\"Column\":{\"Expression\":{\"S
ourceRef\":{\"Entity\":\"servers_and_applications\"}},\"Prop
erty\":\"App Name\"}}},{\"displayName\":\"Cust_Nme\",\"quer
yName\":\"servers_and_applications.Cust_Nme\",\"roles\":{\"V
alues\":true},\"type\":{\"category\":null,\"underlyingType\
":1},\"expr\":{\"Column\":{\"Expression\":{\"SourceRef\":{\"
Entity\":\"servers_and_applications\"}},\"Property\":\"Cust
_Nme\"}}},{\"displayName\":\"MU_ID\",\"queryName\":\"servers
_and_applications.MU_ID\",\"roles\":{\"Values\":true},\"typ
e\":{\"category\":null,\"underlyingType\":1},\"expr\":{\"Col
umn\":{\"Expression\":{\"SourceRef\":{\"Entity\":\"servers_
and_applications\"}},\"Property\":\"MU_ID\"}}}]}"}],"config"
:"{}","displayOption":1,"width":1280,"height":720}],"config
":"{\"version\":\"3.19\",\"themeCollection\":{\"baseTheme\":
{\"name\":\"CY18SU07\",\"version\":\"3.22\",\"type\":2}},\"
activeSectionIndex\":0,\"defaultDrillFilterOtherVisuals\":tr
ue,\"settings\":{\"useStylableVisualContainerHeader\":true,
\"exportDataMode\":1}}","layoutOptimization":0}
At line:1 char:46
  $myJson = Get-Content cleantest2.json -Raw | ConvertFrom-Json
                                               ~~~~~~~~~~~~~~~~
      CategoryInfo          : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
      FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

Below is file that was trying to get parsed.

{"id":0,"resourcePackages":[{"resourcePackage":{"name":"SharedResources","type":2,"items":[{"type":202,"path":"BaseThemes/CY18SU07.json","name":"CY18SU07"}],"disabled":false}}],"sections":[{"id":0,"name":"ReportSection","displayName":"Page 1","filters":"[]","ordinal":0,"visualContainers":[{"x":10,"y":0,"z":1,"width":280,"height":280,"config":"{\"name\":\"5a0b8ef6c97162087ff7\",\"layouts\":[{\"id\":0,\"position\":{\"x\":10,\"y\":0,\"width\":280,\"height\":280,\"z\":1}}],\"singleVisual\":{\"visualType\":\"tableEx\",\"projections\":{\"Values\":[{\"queryRef\":\"servers_and_applications.App Name\"},{\"queryRef\":\"servers_and_applications.Cust_Nme\"},{\"queryRef\":\"servers_and_applications.MU_ID\"}]},\"prototypeQuery\":{\"Version\":2,\"From\":[{\"Name\":\"s\",\"Entity\":\"servers_and_applications\"}],\"Select\":[{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},\"Property\":\"App Name\"},\"Name\":\"servers_and_applications.App Name\"},{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},\"Property\":\"Cust_Nme\"},\"Name\":\"servers_and_applications.Cust_Nme\"},{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},\"Property\":\"MU_ID\"},\"Name\":\"servers_and_applications.MU_ID\"}]},\"drillFilterOtherVisuals\":true}}","filters":"[]","query":"{\"Commands\":[{\"SemanticQueryDataShapeCommand\":{\"Query\":{\"Version\":2,\"From\":[{\"Name\":\"s\",\"Entity\":\"servers_and_applications\"}],\"Select\":[{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},\"Property\":\"App Name\"},\"Name\":\"servers_and_applications.App Name\"},{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},\"Property\":\"Cust_Nme\"},\"Name\":\"servers_and_applications.Cust_Nme\"},{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},\"Property\":\"MU_ID\"},\"Name\":\"servers_and_applications.MU_ID\"}]},\"Binding\":{\"Primary\":{\"Groupings\":[{\"Projections\":[0,1,2],\"Subtotal\":1}]},\"DataReduction\":{\"DataVolume\":3,\"Primary\":{\"Window\":{\"Count\":500}}},\"Version\":1}}}]}","dataTransforms":"{\"projectionOrdering\":{\"Values\":[0,1,2]},\"queryMetadata\":{\"Select\":[{\"Restatement\":\"App Name\",\"Name\":\"servers_and_applications.App Name\",\"Type\":2048},{\"Restatement\":\"Cust_Nme\",\"Name\":\"servers_and_applications.Cust_Nme\",\"Type\":2048},{\"Restatement\":\"MU_ID\",\"Name\":\"servers_and_applications.MU_ID\",\"Type\":2048}]},\"visualElements\":[{\"DataRoles\":[{\"Name\":\"Values\",\"Projection\":0,\"isActive\":false},{\"Name\":\"Values\",\"Projection\":1,\"isActive\":false},{\"Name\":\"Values\",\"Projection\":2,\"isActive\":false}]}],\"selects\":[{\"displayName\":\"App Name\",\"queryName\":\"servers_and_applications.App Name\",\"roles\":{\"Values\":true},\"type\":{\"category\":null,\"underlyingType\":1},\"expr\":{\"Column\":{\"Expression\":{\"SourceRef\":{\"Entity\":\"servers_and_applications\"}},\"Property\":\"App Name\"}}},{\"displayName\":\"Cust_Nme\",\"queryName\":\"servers_and_applications.Cust_Nme\",\"roles\":{\"Values\":true},\"type\":{\"category\":null,\"underlyingType\":1},\"expr\":{\"Column\":{\"Expression\":{\"SourceRef\":{\"Entity\":\"servers_and_applications\"}},\"Property\":\"Cust_Nme\"}}},{\"displayName\":\"MU_ID\",\"queryName\":\"servers_and_applications.MU_ID\",\"roles\":{\"Values\":true},\"type\":{\"category\":null,\"underlyingType\":1},\"expr\":{\"Column\":{\"Expression\":{\"SourceRef\":{\"Entity\":\"servers_and_applications\"}},\"Property\":\"MU_ID\"}}}]}"}],"config":"{}","displayOption":1,"width":1280,"height":720}],"config":"{\"version\":\"3.19\",\"themeCollection\":{\"baseTheme\":{\"name\":\"CY18SU07\",\"version\":\"3.22\",\"type\":2}},\"activeSectionIndex\":0,\"defaultDrillFilterOtherVisuals\":true,\"settings\":{\"useStylableVisualContainerHeader\":true,\"exportDataMode\":1}}","layoutOptimization":0}

Reformatted:

{
    "id":  0,
    "resourcePackages":  [
                             {
                                 "resourcePackage":  {
                                                         "name":  "SharedResources",
                                                         "type":  2,
                                                         "items":  [
                                                                       {
                                                                           "type":  202,
                                                                           "path":  "BaseThemes/CY18SU07.json",
                                                                           "name":  "CY18SU07"
                                                                       }
                                                                   ],
                                                         "disabled":  false
                                                     }
                             }
                         ],
    "sections":  [
                     {
                         "id":  0,
                         "name":  "ReportSection",
                         "displayName":  "Page 1",
                         "filters":  "[]",
                         "ordinal":  0,
                         "visualContainers":  [
                                                  {
                                                      "x":  10,
                                                      "y":  0,
                                                      "z":  1,
                                                      "width":  280,
                                                      "height":  280,
                                                      "config":  "{\"name\":\"5a0b8ef6c97162087ff7\",\"layouts\":[{\"id\":0,\"position\":{\"x\":10,\"y\":0,\"width\":280,\"height\":280,\"z\":1}}],\"singleVisual\":{\"visualType\":\"tableEx\",\"projections\":{\"Values\":[{\"queryRef\":\"servers_and_applications.App Name\"},{\"queryRef\":\"servers_and_applications.Cust_Nme\"},{\"queryRef\":\"servers_and_applications.MU_ID\"}]},\"prototypeQuery\":{\"Version\":2,\"From\":[{\"Name\":\"s\",\"Entity\":\"servers_and_applications\"}],\"Select\":[{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},\"Property\":\"App Name\"},\"Name\":\"servers_and_applications.App Name\"},{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},\"Property\":\"Cust_Nme\"},\"Name\":\"servers_and_applications.Cust_Nme\"},{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},\"Property\":\"MU_ID\"},\"Name\":\"servers_and_applications.MU_ID\"}]},\"drillFilterOtherVisuals\":true}}",
                                                      "filters":  "[]",
                                                      "query":  "{\"Commands\":[{\"SemanticQueryDataShapeCommand\":{\"Query\":{\"Version\":2,\"From\":[{\"Name\":\"s\",\"Entity\":\"servers_and_applications\"}],\"Select\":[{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},\"Property\":\"App Name\"},\"Name\":\"servers_and_applications.App Name\"},{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},\"Property\":\"Cust_Nme\"},\"Name\":\"servers_and_applications.Cust_Nme\"},{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s\"}},\"Property\":\"MU_ID\"},\"Name\":\"servers_and_applications.MU_ID\"}]},\"Binding\":{\"Primary\":{\"Groupings\":[{\"Projections\":[0,1,2],\"Subtotal\":1}]},\"DataReduction\":{\"DataVolume\":3,\"Primary\":{\"Window\":{\"Count\":500}}},\"Version\":1}}}]}",
                                                      "dataTransforms":  "{\"projectionOrdering\":{\"Values\":[0,1,2]},\"queryMetadata\":{\"Select\":[{\"Restatement\":\"App Name\",\"Name\":\"servers_and_applications.App Name\",\"Type\":2048},{\"Restatement\":\"Cust_Nme\",\"Name\":\"servers_and_applications.Cust_Nme\",\"Type\":2048},{\"Restatement\":\"MU_ID\",\"Name\":\"servers_and_applications.MU_ID\",\"Type\":2048}]},\"visualElements\":[{\"DataRoles\":[{\"Name\":\"Values\",\"Projection\":0,\"isActive\":false},{\"Name\":\"Values\",\"Projection\":1,\"isActive\":false},{\"Name\":\"Values\",\"Projection\":2,\"isActive\":false}]}],\"selects\":[{\"displayName\":\"App Name\",\"queryName\":\"servers_and_applications.App Name\",\"roles\":{\"Values\":true},\"type\":{\"category\":null,\"underlyingType\":1},\"expr\":{\"Column\":{\"Expression\":{\"SourceRef\":{\"Entity\":\"servers_and_applications\"}},\"Property\":\"App Name\"}}},{\"displayName\":\"Cust_Nme\",\"queryName\":\"servers_and_applications.Cust_Nme\",\"roles\":{\"Values\":true},\"type\":{\"category\":null,\"underlyingType\":1},\"expr\":{\"Column\":{\"Expression\":{\"SourceRef\":{\"Entity\":\"servers_and_applications\"}},\"Property\":\"Cust_Nme\"}}},{\"displayName\":\"MU_ID\",\"queryName\":\"servers_and_applications.MU_ID\",\"roles\":{\"Values\":true},\"type\":{\"category\":null,\"underlyingType\":1},\"expr\":{\"Column\":{\"Expression\":{\"SourceRef\":{\"Entity\":\"servers_and_applications\"}},\"Property\":\"MU_ID\"}}}]}"
                                                  }
                                              ],
                         "config":  "{}",
                         "displayOption":  1,
                         "width":  1280,
                         "height":  720
                     }
                 ],
    "config":  "{\"version\":\"3.19\",\"themeCollection\":{\"baseTheme\":{\"name\":\"CY18SU07\",\"version\":\"3.22\",\"type\":2}},\"activeSectionIndex\":0,\"defaultDrillFilterOtherVisuals\":true,\"settings\":{\"useStylableVisualContainerHeader\":true,\"exportDataMode\":1}}",
    "layoutOptimization":  0
}

Items attempted:

  • Used online formator on text and then re-ran command on resulting string. - Worked
  • Tried to import raw string and export as JSON using ConverTo-Json method but didn't work correctly.
  • Tried parsing using Python but had similar issue.

CodePudding user response:

I was able to fix this by changing the encoding to unicode. See below sample execution.

$myJson = Get-Content cleantest2.json -Encoding unicode | ConvertFrom-Json

CodePudding user response:

screenshot


[1] Use of Format-Hex to discover (non-ASCII-range) Unicode characters isn't an option in Windows PowerShell, because it represents any non-ASCII chars. as 3f, i.e. literal ?. In PowerShell (Core) it shows the ASCII rendering of the individual bytes that make up the UTF-8 encoding of non-ASCII characters, which can be confusing.

  • Related