Create Record from JSON format?

sri83
Tera Guru

Hi Team,

 

I have created the Schedule job and called the Datasoure in it. when we execute the schedule job JSON data will attach to Datasourece dynamically as below format and it will process through Transform map and create records in Source and Target Records.

 

But My JSON format is showing wrong and it's not creating any records in Source and target table please help me on this.

 

Error:

java.lang.IllegalStateException: JSON input starting with a JSON Array is not supported ( scheduled import job: E360 Guardrail Data Upload_JSON)

 

JSON:

var str = '{"state":2,"httpCode":200,"response":"{\"Ticket\" : \"061cech41hh7e27c86f88b08c8fd2a\",\"StatusCode\" : \"201 Created\",\"Message\" : \"Record Created.\"}"}';

 

var str = JSON.stringify(str );
 str = str.replace(/\\/g,"");
var json_data = JSON.parse(str);
gs.info(json_data);
1 REPLY 1

mdash
Giga Guru

Hi @sri83 ,

Since you are generating the JSON from scheduled job, can you adjust your script to create the final output as something like this?

{"state":"2","httpCode":"200","response":{"Ticket" : "061cech41hh7e27c86f88b08c8fd2a","StatusCode" : "201 Created","Message" : "Record Created."}};

1)2 and 200 are in quotes
2)In your script if you are making JSON.stringify(response), you can remove that, it is adding extra '\'.

It will be easy to control from source rather than parse/replace at the transform script. 

Let me know if that works, or if you can share your schedule job part where you are creating this JSON, I can have a look.

You can mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards