Question

How to remove square brackets in a json file?


Hello

I am generating a json file for photographs metadata.

At the start and end of the file I have an open bracket and a closed bracket. I don't want to have this square brackets in the generated json file.

Thankscrochet_json


3 replies

Userlevel 4

The square brackets indicate an array of objects, and the FME JSON writer will output them even when there is only a single feature.

The easiest is probably to use the JSONTemplater to generate the JSON contents according to your specification and to write the results using the Text File writer.

Can I position the JsonTemplater before generating the json file or do I have to generate the json file first and then apply the formatting ?position_jsontemplate

Userlevel 5
Badge +29

Even though I prefer @david_r​ answer, another approach would be to use an AttributeTrimmer to remove the leading "[" and trailing "]". I wouldn't suggest a StringReplacer as that could break valid arrays in the JSON

Reply