Skip to main content
Solved

Multiple Records out to the same JSON file

  • September 26, 2019
  • 4 replies
  • 185 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:

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • 1637 replies
  • 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
  • 7 replies
  • 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:

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
  • 1637 replies
  • September 26, 2019

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
  • 7 replies
  • September 26, 2019

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!!