Skip to main content
Question

How to remove square brackets in a json file?

  • April 6, 2023
  • 3 replies
  • 775 views

claireco
Contributor
Forum|alt.badge.img+2

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
  • 8392 replies
  • 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+2
  • Author
  • Contributor
  • 6 replies
  • 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+63
  • Celebrity
  • 1625 replies
  • 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