Converting dictionary to a different JSON response

Hi,

How can I convert the below dictionary-

{
name:"Vivek",
place:"XYZ"
}
to something like this:
"{\"name\":\"Vivek\",\"place\":\"XYZ\"}"
It is a bit from what a!toJson function returns. Any lead will be helpful.
Thanks!

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    Hi Vivek

    Please try the below code  which is closer to your output.

    a!localVariables(
    local!data:{
    {name:"Vivek",
    place:"XYZ"}
    } ,
    local!final:substitute(insertkeyval("name",local!data["name"],"\","\"),"=","\:\"),
    local!final2:substitute(insertkeyval("place",local!data["place"],"\","\"),"=","\:\"),
    local!data2:concat(local!final,",",local!final2),
    local!data2

    )

    sample output "\name\:\Vivek\,\place\:\XYZ\"

Reply
  • 0
    Certified Senior Developer

    Hi Vivek

    Please try the below code  which is closer to your output.

    a!localVariables(
    local!data:{
    {name:"Vivek",
    place:"XYZ"}
    } ,
    local!final:substitute(insertkeyval("name",local!data["name"],"\","\"),"=","\:\"),
    local!final2:substitute(insertkeyval("place",local!data["place"],"\","\"),"=","\:\"),
    local!data2:concat(local!final,",",local!final2),
    local!data2

    )

    sample output "\name\:\Vivek\,\place\:\XYZ\"

Children
No Data