Solved

Multiple Records out to the same JSON file

  • 26 September 2019
  • 4 replies
  • 51 views

Badge

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

icon

Best answer by daveatsafe 26 September 2019, 21:11

View original

4 replies

Userlevel 2
Badge +17

Hi @richardsr,

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

Badge

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?

 

 

Userlevel 2
Badge +17

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.

Badge

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

Reply