Skip to main content
Solved

Multiple Records out to the same JSON file

  • September 26, 2019
  • 4 replies
  • 150 views

richardsr
Contributor
Forum|alt.badge.img+1

Hello Community,

I am having some challenges writing multiple records into a valid json output. What I have is working using a text writer but it is missing the comma "," between the individual records. I was about to explore building a list and change my json template or do i need an aggregate? I seem to be confusing myself with this small detail.

Below is an example of my current output into a text writer. I pretty much followed the Json Writer article (https://knowledge.safe.com/articles/44294/json-writing-with-jsontemplater.html ) which was a huge help but the difference here is I am fanning the output by date so multiple records will be written I just cannot figure out how to make the json valid.

20190711.json

I believe just need a comma to separate these 2 records to make it valid

Any help would be appreciated!!

Thanks

Ronnie

Best answer by daveatsafe

Hi @richardsr,

I think another JSONTemplater might be the best idea - it will both add the commas and the surrounding '[]' for the array:

View original
Did this help you find an answer to your question?

4 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • Best Answer
  • September 26, 2019

Hi @richardsr,

I think another JSONTemplater might be the best idea - it will both add the commas and the surrounding '[]' for the array:


richardsr
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • September 26, 2019
daveatsafe wrote:

Hi @richardsr,

I think another JSONTemplater might be the best idea - it will both add the commas and the surrounding '[]' for the array:

Thank you so much for the quick response and suggestion. This looks really close now and the only issue I have not is it seems to be escaping the valid json which was being passed into the SUB template. Any ideas how to remove the extra " & \\ characters?

 

 


daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • September 26, 2019
richardsr wrote:

Thank you so much for the quick response and suggestion. This looks really close now and the only issue I have not is it seems to be escaping the valid json which was being passed into the SUB template. Any ideas how to remove the extra " & \\ characters?

 

 

You need to use fme:get-json-attribute("text_line_data") instead of fme:get-attribute("text_line_data"). This will not escape the JSON.


richardsr
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • September 26, 2019
daveatsafe wrote:

You need to use fme:get-json-attribute("text_line_data") instead of fme:get-attribute("text_line_data"). This will not escape the JSON.

That was it!! Thank you so much!!


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