Solved

json writer/stream

  • 14 June 2018
  • 1 reply
  • 1 view

Badge +10

Hi,

I am writing out to a json writer and intend to stream this json using fme cloud.

0684Q00000ArD5bQAF.png

The output looks like 

[
{
"STAGING_ID" : "9515",
"USER_API" : "A2C3601C-40E9-48DC-A0C0-5D4DB0867A2E",
"REQUEST_GUID" : "80318a93-f513-4e63-8c08-9e07250af0e2",
"ID" : "120654",
"UNIQUE_LOCATION_ID" : "5819",
"UNIQUE_SAMPLE_ID" : "576683",
"ROW_CREATED_DATE" : "18/05/2010",
"LAST_EDITED_DATE" : "18/08/2017",
etc

Ideally I would like to add a few lines before the records return e.g.

[
    "status":"ok", 
    "body" : 
{
"STAGING_ID" : "9515",
"USER_API" : "A2C3601C-40E9-48DC-A0C0-5D4DB0867A2E",
"REQUEST_GUID" : "80318a93-f513-4e63-8c08-9e07250af0e2",
"ID" : "120654",
"UNIQUE_LOCATION_ID" : "5819",
"UNIQUE_SAMPLE_ID" : "576683",
"ROW_CREATED_DATE" : "18/05/2010",
"LAST_EDITED_DATE" : "18/08/2017",

Could anyone suggest how this can be achieved. I really don't want to manually template the output from the rows because they are dynamic and remove any null values.

Many Thanks,

Oliver

icon

Best answer by takashi 14 June 2018, 15:04

View original

1 reply

Userlevel 2
Badge +17

Hi @olivermorris, a possible way is: write the JSON document above with the FeautreWriter (Format: JSON), read back the resulting document with the FeatureReader (Format: Text File, Read Whole File At Once: Yes), extract the "body" { contents of body } with the JSONFragmenter, finally create your desired JSON object {"status" : "ok", "body" : { contents of body }} with the JSONTemplater.

Reply