How to transform a json to another?

My webhook receive some data that respect a data structure, let say

{"user":"albert",
 "items":[
   {"name":"productA","value":10}
   {"name":"productB","value":20}
]
}

and i want to send that to a webpage using a form encoded POST, with the following fields

form[user]:albert
form[items][0][name]:productA
form[items][0][value]:10
form[items][1][name]:productB
form[items][1][value]:20

so i guess in the fields of the http request i would use a map that is an array of objects with key and values… but i cant find a way to create that array from the initial json String.

Thank you !

Hey Sebastien,

will the array of items be fixed length or different each time?

If it’s different, you will need to iterate it and use a text aggregator to rebuild it in the new format.

1. Use AI

Example output:

Screenshot_2024-10-10_221027

Map directly in your HTTP module:

Screenshot_2024-10-10_221004

2. Use JavaScript

Hope this helps! Let me know if there are any further questions or issues.

— @samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

1 Like

Thank you for those answers, but i dont want to use an extra system to do this, i would like to do this basic transformation inside the scenario.

Hey Stoyan,

The array doesnt have fixed length. yes i can use a text aggregator in priciple, but i dont see what complete sequence of operations would perform a generic transformation.

Thank you

I found a hack that bring me a step closer.

When you parse my input json and try to use the result, the mappable parameters you can access are only the childs of the root of your json object, not the object itself
image

If you want to access the complete object, what you can do is change the Text value of the parser to encapsulate your json string in a json object with a single property (i.e ‘output’) like this

the output bundle of the parser has a property “output” wich is our Object
image

we can then use the toArray() function to obtain an array of keys and values that can be used as a map
image

Now by iterating on this array I would like , using a router, to treat differently the Values that are Array, Collection or neither.

I cant find an operation that would provide the type of a value, something like typeOf

I tried to use Array specific function like length to detect Array, and Collection specific function like contains to detect Collection, but without success

I think we really need a module that allow to transform a json to another , if you agree please vote for this feature request https://www.make.com/en/platform-ideas/p/a-json-transformation-module