Skip to main content
Question

Make a complex json with multiple sub-objects

  • December 22, 2020
  • 1 reply
  • 72 views

geo-x
Participant
Forum|alt.badge.img
  • Participant

Dear FME community.

 

I need help for using the JsonTemplater transformer.

I've multiple data source and I've to build a complex json with sub objects like that (this is with only one level but in the real case I've more sublevels) :

eeeeI make an unperfect example join to this question :-)

 

Thanks for your help.

1 reply

tomf
Contributor
Forum|alt.badge.img+14
  • Contributor
  • January 14, 2021

To use the JSONTemplater with "sub-levels" you should make use of the Sub Templates in the transformer:

JSONTemplator_parametersHere I've created the Root of the json document as:

JSONTemplator_rootWith SUB_ROOT and SUB_SUB_ROOT templates defined in the Sub Templates section as:

JSONTemplator_subrootand

JSONTemplator_subsubrootrespectively. The call in SUB_ROOT to bring in the SUB_SUB_ROOT template includes paramters to only include the sub-sub-features that are associated with the sub-feature. In this case both features have the same "sub_feat" value.

All you need to do is then send into the JSONTemplator features for each level, one for each Root, then all the sub-level and finally all the sub-sub-level features into their allocated input ports. Grouping of the subfeatures occurs when they carry the same feature identification attribute value as is present on the level above.

 

Running some sample data through the JSONTemplator and JSONFormatter (for PrettyPrint) we get:

JSON_outputI hope this help you to solve your json issue.


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