Skip to main content
Question

How to remove square brackets in a json file?


claireco
Contributor
Forum|alt.badge.img+1

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

david_r
Celebrity
  • April 6, 2023

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.


claireco
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • April 6, 2023

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


hkingsbury
Celebrity
Forum|alt.badge.img+53
  • Celebrity
  • April 10, 2023

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


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