Hi All,
I required to generate JSON in the below format for the data that needs to be sent to another system thru integration:
Req format:
"[{\"ods_service_affected\":\"testetset\",\"ods_outage_start_datetime\":\"2021-11-30 13:00:00\",\"ods_outage_end_datetime\":\"2021-12-01 22:18:45\",\"ods_utage_duration_requested\":\"02 01:00:00\",\"ods_effect_on_site\":\"off\"},{\"ods_service_affected\":\"1213546\",\"ods_outage_start_datetime\":\"2021-12-01 13:00:00\",\"ods_outage_end_datetime\":\"2021-12-02 22:19:09\",\"ods_utage_duration_requested\":\"01 05:00:00\",\"ods_effect_on_site\":\"lor\"}]"
As you can see there are escape characters that were added to the JSON. I tried adding those escape characters however I noticed an additional double quote is getting added to the string. It looks like by default double quotes are added to the values by JSON
Below is my code:
"""ods_service_affected""": """" & fv!item.serviceAffected & """", """ods_outage_start_datetime""": """" & fv!item.outageStartDateTime & """", """ods_outage_end_datetime""": """" & fv!item.outageEndDateTime & """", """ods_utage_duration_requested""": """" & fv!item.outageDurationRequested & """", """ods_effect_on_site""": """" & fv!item.effectOnSite
Generated JSON:
[{"\"ods_service_affected\"":"\"Service number 1\"","\"ods_outage_start_datetime\"":"\"24/12/2021 09:30 GMT+11:00\"","\"ods_outage_end_datetime\"":"\"25/12/2021 10:00 GMT+11:00\"","\"ods_utage_duration_requested\"":"\"01 02:03:04\"","\"ods_effect_on_site\"":"\"swg"},{"\"ods_service_affected\"":"\"Service number 2\"","\"ods_outage_start_datetime\"":"\"25/12/2021 04:00 GMT+11:00\"","\"ods_outage_end_datetime\"":"\"25/12/2021 05:00 GMT+11:00\"","\"ods_utage_duration_requested\"":"\"00 00:30:00\"","\"ods_effect_on_site\"":"\"rpw"},{"\"ods_service_affected\"":"\"Service number 3\"","\"ods_outage_start_datetime\"":"\"24/12/2021 21:00 GMT+11:00\"","\"ods_outage_end_datetime\"":"\"24/12/2021 23:00 GMT+11:00\"","\"ods_utage_duration_requested\"":"\"00 00:00:17\"","\"ods_effect_on_site\"":"\"off"}]}
Please provided your valuable suggestions to remove additional quotes.
Discussion posts and replies are publicly visible
The required format is not valid JSON. I think that someone who provided that string escaped the quotation marks.
Do not try to create the JSON strings yourself! Create the data structure as Appian Maps or Dictionaries and use the a!toJson() function. Like in Acacios example.
Thank u Acacio and Stefan. That did the trick. Appreciate ur help