Skip to main content
Question

Make a complex json with multiple sub-objects

  • December 22, 2020
  • 1 reply
  • 94 views

geo-x
Supporter
Forum|alt.badge.img+6

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.

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.

1 reply

tomf
Supporter
Forum|alt.badge.img+20
  • Supporter
  • 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.