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
Hi Ashoku,
I'm pretty sure that this is not the answer for your question and probably there will be a smarter way to do it, but it's an idea:
a!localVariables( local!a: { a!map( ods_service_affected: "testetset", ods_outage_start_datetime: now(), ods_outage_end_datetime: now(), ods_utage_duration_requested: today(), ods_effect_on_site: "off" ), a!map( ods_service_affected: "testetsetV2", ods_outage_start_datetime: now(), ods_outage_end_datetime: now(), ods_utage_duration_requested: today(), ods_effect_on_site: "off" ) }, local!b: a!toJson(local!a), local!c: regexinsertmatchmarkers("\""",local!b,"\",null,false(),"ms" ), local!c )
Hope that helps,
Acacio B.
Your information is very accurate and specific. I applied it! 1v1 lol