I’m trying to build JSON in a logic block to be used in an outbound endpoint call and curious how I would be able to achieve building a structure like this:
I’ve tried using the JSON object and array and get errors about not being able to set a value into a json object that is not an object or something similar and curious if it’s possible to build what I need using the JSON object and JSON array data types.
Hi Mike, you should be able to do this in logic blocks using several Set Values actions. Here is the general idea:
instantiate a new variable of type JSON Object to hold your entire JSON structure
instantiate a new variable of type JSON Array to hold your service array
it’s not clear to me how you are grabbing the values to populate the service array, but let’s say it comes from a record fetch. In the data found loop, you will create a Set Values action whose “Action” is “Add” and in the “To” field, select your JSON Array variable. Then in the “From” field, select the field from the table that represents the values you want.
after you have populated the JSON Array (outside the loop), add another Set Values action. Inside this action, you will assign the service JSON Array to a key in your JSON Object variable. This will be a set operation and in the “To” field, will specify “services” as the Object Key and select “Json Array” as the Object Key Data Type. In the “From” field, you will select your existing JSON Array variable. You now should have a fully formed JSON object in the structure you have described.
The key idea here is that you build the JSON Array separately from the JSON Object and then once the array is fully formed, you can add it to your JSON Object.
I know this is a bit involved, but this should solve your use case. Don’t hesitate to reach out if you have further questions!