What you can do is insert a Counter transformer before the writer, it will simply number each feature coming through with an incremental number and you can write that to an attribute. Don't forget to add the attribute to your GeoJSON writer though! (in the User Attributes tab of the writer feature type properties).
Thank you for the answer. It seems though that the attribute is added to the properties of the feature and not to the feature itself as in the example.
Would it be possible to share a small example of what you currently have and what you want to have?
Would it be possible to share a small example of what you currently have and what you want to have?
I have uploaded a sample GeoJSON😊. I would like the ID-attribute to be at the features-level.
I have uploaded a sample GeoJSON😊. I would like the ID-attribute to be at the features-level.
Ah, I see. I think you can't do that under the GeoJSON specs, from what I've been able to find out you can only have type, geometry and properties at the features level. The FME writer will add all attributes at the properties level.
Hi, I am new to this topic and have exactly the same problem. I would be interested to know if you have found a solution in the meantime?Â
Hi, I am new to this topic and have exactly the same problem. I would be interested to know if you have found a solution in the meantime?Â
Hi, I didnt manage to add the id where I wanted it. I ended up opening the geojson file in QGIS and exported it with an id that way, although this way it is difficult to automate.
Thanks, this is the way, that i will take too.
Hi,
I had the same problem and this is how I solved it with python:
Create the geojson file with a FeatureWriter. In the summary output port you get the output path as "_dataset" attribute. Connect a PythonCaller to the summary output port and add the following code in the input function:
import json
import os
n...]
def input(self, feature):
    filename = feature.getAttribute('_dataset')
    with open(filename, 'r', encoding='utf8') as file:
        data = json.load(file)
        for f in dataf"features"]:
            f "id"] = fo"properties"]>"id"]
Â
    os.remove(filename)
    with open(filename, 'w', encoding='utf8') as f:
        json.dump(data, f, ensure_ascii=False)
Â
Â