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
  • 98 views

salvaleonrp
Enthusiast
Forum|alt.badge.img+15

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.

View original
Did this help you find an answer to your question?

4 replies

takashi
Supporter
  • 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+15
  • Author
  • Enthusiast
  • March 1, 2020

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


david_r
Evangelist
  • 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+15
  • Author
  • Enthusiast
  • March 10, 2020
david_r wrote:

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.

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings