Skip to main content
Solved

JSON Result contains schema array and features array - how can I use the schema array to expose attribute names when I flatten the features array

  • February 29, 2020
  • 4 replies
  • 149 views

salvaleonrp
Enthusiast
Forum|alt.badge.img+20

The gist of the problem was defined in this question. https://knowledge.safe.com/questions/46298/how-can-i-easily-expose-attributes-from-xmlflatten.html

In my case the JSON has the schema (name, alias and field type of a feature). Shown below.

Sample attached.

I got the schema array in rows.

I have feautes JSON fragmented with json["features"][*]["attributes"] with the following output.

Instead of exposing each attribute one at a time or importing a temporary csv file created by aggregation, i'd like to use the schema from the fields array for the features output.

Hope to get some ideas to use using derived schema in my workflow.

Thanks!

Best answer by takashi

Hi @salvaleonrp, in this case, I think you can apply the dynamic workflow approach described in Dynamic Workflows: Destination Schema is Derived from a Schema Feature. That is, create schema definition (attribute{}.name, attribute{}.fme_data_type) from the JSON "fields" array. You can then merge the list to every feature unconditionally in order to configure dynamic writer feature type.

See also the attached workspace example: schema-from-json-array.fmwt (FME 2019.2.3.1)

Note: the original format of "creationdate" seems to be milliseconds since UNIX epoch, so you will have to expose it and convert the format to an appropriate date/time format for the destination data format.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

takashi
Celebrity
  • 7842 replies
  • Best Answer
  • March 1, 2020

Hi @salvaleonrp, in this case, I think you can apply the dynamic workflow approach described in Dynamic Workflows: Destination Schema is Derived from a Schema Feature. That is, create schema definition (attribute{}.name, attribute{}.fme_data_type) from the JSON "fields" array. You can then merge the list to every feature unconditionally in order to configure dynamic writer feature type.

See also the attached workspace example: schema-from-json-array.fmwt (FME 2019.2.3.1)

Note: the original format of "creationdate" seems to be milliseconds since UNIX epoch, so you will have to expose it and convert the format to an appropriate date/time format for the destination data format.


salvaleonrp
Enthusiast
Forum|alt.badge.img+20
  • Author
  • Enthusiast
  • 151 replies
  • March 1, 2020

@takashi I really appreciate the help. That's awesome! Thanks!


david_r
Celebrity
  • 8391 replies
  • March 5, 2020

I'm a bit late to the party, but is this possibly some ESRI-flavored JSON? What happens if you try reading it with the "Esri-JSON (Esri JavaScript Object Notation)" reader?


salvaleonrp
Enthusiast
Forum|alt.badge.img+20
  • Author
  • Enthusiast
  • 151 replies
  • March 10, 2020

I'm a bit late to the party, but is this possibly some ESRI-flavored JSON? What happens if you try reading it with the "Esri-JSON (Esri JavaScript Object Notation)" reader?

It is a json response to a ArcGIS Server capability called Export Subnetwork.

 

 

I used the ESRI-JSON format reader but all it does is flatten the features array into attributes- which does it very well. However, I need to use another array in the same json called "fields" for sourceMapping actual values of the features' attributes, e.g. fromnetworksourceid --> sourceAlias; layerId --> featureLayerName.

 

 

Also, my Json Url queries have a lot of parameters to make it practical to use the ESRI-JSON reader.

Newer references for ESRI JSON below.

 

https://developers.arcgis.com/rest/services-reference/output-formats.htm

 

https://www.json.org/json-en.html

 

 

Thanks for your response @david_r.