Question

Decode JSON


Badge

Hello, JSON-lovers!

We've been trying to extract the attributes from this response body but however we do it seems like we need to input the attributes we need manually. This can't be true. We would like to get all the attributes no matter what. We're no JSON-specialist as you can probably guess... Is there an easy way to do this?

Response body:

[{"ObjectId":507,"ComponentId":3,"Metadata":{"KomponentNamn":"AB+56232=270XO001","Lansbokstav":"AB","Objekt":"56","ObjektId":507,"KomponentId":3,"Area":"2","Placering":"32","System":"27","Underniv":"0","Beteckning":"XO","Nr":"001","Underlitt":"","Beskrivning":"Övrigt konstruktionselement, Polygonpunkt","Entreprenor":"","Leverantor":"Ab Tolle","Tillverkare":"","X":6570455.3729,"Y":143139.124,"Z":0.0,"SlutX":0.0,"SlutY":0.0,"SlutZ":0.0,"Grupp":"Admin","Kommun":null,"Vagnr":null,"PlaceringVagomr":null,"Rumsbeteckning":"","Artikelnr":"","Markning":"","GPDOmrade":null,"Entreprenad":"","Driftomrade":"","KomponentStatus":0,"KompStatus":"Ny/reserverad","Valfri1":"","Valfri2":"","Valfri3":"","Valfri4":"","Valfri5":"","XTM":6571368.807,"YTM":664217.876,"ZTM":0.0,"SlutXTM":0.0,"SlutYTM":0.0,"SlutZTM":0.0,"OverordnadELKRAFT":null,"OverordnadTEKNIK":null,"OverordnadSTYR":null},"Documents":[...TRUNCATED...],"Attributes":[]}]


2 replies

Userlevel 2
Badge +17

Hi @peteralstorp,

The JSONFragmenter transformer can break up the JSON into features, and extract the feature attributes for you, if you set Flatten Query Result into Attributes to 'Yes'.

The transformer does not automatically expose the extracted attributes for you, since the content of the JSON is not known until the workspace is run. You will need to expose the attributes you need to work with (ie. X and Y) manually.

The rest of the attributes can automatically be included on the writer output, if you use dynamic writing, and supply a schema on the features. The FME Hub transformer SchemaSetter will create the schema for you.

Most writers do not support lists in their schemas, so you will need to explode the Documents{} list on your features before sending to the SchemaSetter, to create a separate feature for each entry in the Document list.

Badge

Sounds perfect, try it tomorrow! Thanks a lot!

Reply