Construct nested JSON for API call with JSON_Objectify
Question

Hi,

this is probably not so complicated but I got stuck.

I have a REST API I want to post a nested JSON to.

In the IDE wizard I had success testing the API with the following JSON (which I entered manually in the Request Body)

  "description": "Testing",

  "templateId":"ff1ewa0c-xxxx-45b1-a8e9-ef6975c312bb",

  "templateData": { 

    "Text1": "First text",

    "Text2": "Second Text"

  }

}


At the top right of the image you can see the Outsystems variable "RequestJSON" with the nesting structure (also see at the bottom the "Name in JSON".

I tried to use JSONSerialize and Outsystems2JSON (from the ArdoJSON app). 

For some reason JSON_Objectify is not cleaning the Key:Value pairs. 

The Output from JSON_Objectify is:

"{""templateData"":[{""id"":""Text1"",""value"":""test""},{""id"":""Text2"",""value"":""test2""}],""templateID"":""ff1ewa0c-xxxx-45b1-a8e9-ef6975c312bb""}"

Any idea what I'm doing wrong?

Thank you so much!

Hi Christoph,

Can you change the structure same as below "key , value" in small letters and than try . Attached is the working oml


Also change the path

Best Regards

Devendra


JSONData (1).oml

Hi Devendra,

that was it! Just that the nested structure needs to have parameters called "key" and "value" otherwise Objectify doesn't seem to catch them.

Thanks so much for your help :)

And to add more help for others who run into this: You'll need to put the JSON_Objectify action in the OnBeforeRequest action of your RESTAPI call!

1. Use your Outsystems Variable as an input parameter to your REST API

2. Create an OnBeforeRequest Action and use JSON_Objectify on the input parameter "Request.RequestText". Assign it to the output parameter.

3. Make sure "Request Format" of your call is "JSON"

There is no need to use JSONSerialize or Listify

Hi Christoph,

Please find attached sample oml . I have used JSON_Listfy and JSON_Objectify with your data successfully you can refer that.

Also you can test your data with the below URL. 

https://jnb.outsystemscloud.com/ardoJSONReactiveDemo/JSON_Objectify


 


JSONData.oml

Hi Devendra,

thanks for checking into this issue.

Unfortunately my starting point is not clean JSON which I can run through JSON_Listfy but an Outsystems variable. 

Interestingly the JSON produced from JSON_Listfy and JSONSerializse action looks the same in the debugger, however, only the JSON coming from Listify is converted correctly from JSON_Objectify.

I changed your oml a little to show the issue, would be greatful if you could take a look.

Best

Chris

JSONData (1).oml

Hi Christoph,

Can you change the structure same as below "key , value" in small letters and than try . Attached is the working oml


Also change the path

Best Regards

Devendra


JSONData (1).oml

Hi Devendra,

that was it! Just that the nested structure needs to have parameters called "key" and "value" otherwise Objectify doesn't seem to catch them.

Thanks so much for your help :)

And to add more help for others who run into this: You'll need to put the JSON_Objectify action in the OnBeforeRequest action of your RESTAPI call!

1. Use your Outsystems Variable as an input parameter to your REST API

2. Create an OnBeforeRequest Action and use JSON_Objectify on the input parameter "Request.RequestText". Assign it to the output parameter.

3. Make sure "Request Format" of your call is "JSON"

There is no need to use JSONSerialize or Listify

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.