Skip to main content
Question

How can i create a .json file with the same structure as shown in the image below?


18 replies

itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • September 9, 2016

Hi have you tried the json templater transformer?


david_r
Celebrity
  • September 9, 2016

Looks like GeoJSON, so try the GeoJSON writer.


takashi
Influencer
  • September 9, 2016

Hi @gefo, looks like it's the GeoJSON format. Does the GeoJSON writer help you?


  • Author
  • September 9, 2016

I did use the GeoJSON writer but the structure is not the same. is there a option in FME to change the structure in a GeoJSON file?


takashi
Influencer
  • September 9, 2016
gefo wrote:

I did use the GeoJSON writer but the structure is not the same. is there a option in FME to change the structure in a GeoJSON file?

If you don't need the properties other than "id", you can remove them in the writer feature type (User Attributes tab).

 


  • Author
  • September 9, 2016

Yes i know i can remove Attributes in the writer, but what i need is the same stucture, first the attributes and at lest the geo information.


david_r
Celebrity
  • September 9, 2016
gefo wrote:

Yes i know i can remove Attributes in the writer, but what i need is the same stucture, first the attributes and at lest the geo information.

The objects (type, properties and geometry) are in an unordered list, the order in which they appear in your output should make no difference for practically all use cases.

 

Are you sure this is a problem?

 


  • Author
  • September 9, 2016

I have tried to re-order the original file, and yes its a problem the data wil not load in the webmap, so i need to chance the order. but the question is how can i do that in FME?


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • September 9, 2016

the json templater gives you total control on the schema.


takashi
Influencer
  • September 9, 2016
gefo wrote:

I have tried to re-order the original file, and yes its a problem the data wil not load in the webmap, so i need to chance the order. but the question is how can i do that in FME?

If the order of members is critical, you will have to construct a JSON document with the JSONTemplater as Itay mentioned first.

 


david_r
Celebrity
  • September 9, 2016
gefo wrote:

I have tried to re-order the original file, and yes its a problem the data wil not load in the webmap, so i need to chance the order. but the question is how can i do that in FME?

Sounds like you should complain to the author of the webmap for not following conventions ;-)

 

But yes, the JsonTemplater is the next step.

 


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • September 9, 2016
gefo wrote:

I have tried to re-order the original file, and yes its a problem the data wil not load in the webmap, so i need to chance the order. but the question is how can i do that in FME?

I've asked our JSON developer for an opinion. As far as I can see, nothing in the GeoJSON spec says it has to be Geometry/Properties in that order, but all the examples they show are in that structure. IF it's known to be permitted, and IF a known web mapping tool insists on that order, then we might be able to implement a setting in FME to switch them around.

 


  • Author
  • September 12, 2016

For so far thanks for all the answers, it seems the webmap did not accept using another order in the geojson file, so i will look if i can change the order with the json templater.

The webmap was created with Qgis and Qgis2Web, you can find it here :

https://www.rijssen-holten.nl/data/publicatie-website/_XA000902014C69DADB9778625A8AF871/index1.html?_dc=1459501106970&_dc=1459501107204#11/52.2866/6.4663

All the data in it comes from a postgisDB so its a litle hard to update it with Qgis, in FME it must be easyer, just read the DB and write it to a JSON file in.


takashi
Influencer
  • September 12, 2016

Hi @gefo, if the source point features are read from a PostGIS database, you can convert them to a required JSON document directly with some transformers including the JSONTemplater. e.g.

0684Q00000ArKx8QAF.png

After extracting feature geometry as an attribute (e.g. "_geometry") in GeoJSON format with the GeometryExtractor, send one feature to the Root port of the JSONTemplater and set the Root template:

{
    "type": "FeatureCollection",
    "crs": {
        "type": "name",
        "properties": {
            "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
        }
    },
    "features": fme:process-features("SUB")
}
add a SUB template:
{
    "type": "Feature",
    "properties": {
        "id": fme:get-attribute("id")
    },
    "geometry": fme:get-json-attribute("_geometry")
}
then, send all features to the SUB port.

If there are multiple feature types which should be converted to different JSON documents for each, set feature type identifier attribute to both the "Group By" parameter in the Sampler and the "Group Sub-Features By" parameter in the JSONTemplater


  • Author
  • September 12, 2016

Thanks For the answer i am close to the solution of my problem, the only thing is now how to change the order, it seems the templater does not change the order of the features.


deanatsafe
Safer
Forum|alt.badge.img+6
  • Safer
  • February 8, 2018

Looks like you are trying to write GeoJSON. However, due to a problem with our GeoJSON writer at the moment, our output has some slight differences, particularly when multiple feature types are written. The workaround for now is to use one feature type per dataset, or use dataset fanout. A more comprehensive solution is planned for 2018.1. For more info see: https://knowledge.safe.com/articles/40806/workarounds-to-known-issues-in-fme-20170.html


jnotter
Contributor
Forum|alt.badge.img+5
  • Contributor
  • January 29, 2020
takashi wrote:

Hi @gefo, looks like it's the GeoJSON format. Does the GeoJSON writer help you?

I have a case where the GeoJSON format is not compatible with the output needed (Mapbox GL with each polygon independently colored). I am struggling to figure out how to do JSON Templater or a way to "fix" the GeoJSON output to become compatible.

Goal: output as embedded JSON in a Mapbox html page.


jovitaatsafe
Safer
Forum|alt.badge.img+11
jnotter wrote:

I have a case where the GeoJSON format is not compatible with the output needed (Mapbox GL with each polygon independently colored). I am struggling to figure out how to do JSON Templater or a way to "fix" the GeoJSON output to become compatible.

Goal: output as embedded JSON in a Mapbox html page.

Hi @jnotter,

As this original thread is quite a few years old, would you be open to posting a new question to the Forums? This will increase the visibility of your question and encourage more helpful answers for you from the Community. It would also be helpful to include any screenshots or examples of what you've got currently and what your ideal output would look like. Thanks!


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