Why not create 2 documents and use documentToJsonString twice? It will do all the necessary conversions. Imo you found a workaround to your problem in postman and you are trying to apply it to a different platform. This doesn’t mean you found the correct solution. Your solution works in postman because you are using 2 different quotes in conjunction while assuming json is also a javascript. It should work but it will make a mess that way. If your object is declared like a data object having nested object within it, as in the code below, you don’t need to do anything, just mimic the json object with document and convert it to json.
{
"data": [{
"object1": "value1",
"object2":"value2"
},
{
"object1": "value3",
"object2":"value4"
}]
}
If your object defined as below, you need to call documentToJsonString twice, once for creating the inner jsonobject, second time for outer json object, because your field is not an object instead it is a string. Your example looks like this.
"JsonObject":{
"data":"someOtherJsonString"
}
If you convert your data object twice your inner json object will have \"
instead of "
for enclosing strings. Your solution works because you are using a different quotes chars like we do it in javascript programing, but that’s a manual operation and it can cause inconsistencies. After converting a json object to a json string; it is no longer an object, it is string; hence you need to make proper conversions like using escape chars for quotes. You are not supposed to make any changes (other then escaping some chars) to the jsonString once you create the jsonString. You can definately break it.
Also keep in mind that http.client can produce the outter json object, if you map a document.
#https#webMethods#documenttoJSONString