cancel
Showing results for 
Search instead for 
Did you mean: 

Convert array to object

abjoe
New Contributor II

mapper_output

The output is of the above form. Here root element(Array) is of the form of an array. How do we make it of the form of an object?

wrong_json

To get the idea of the json form, the above is the json view of the output. In that, you can see that “d” is an array.

Correct_json

I want the output to be of the above form. Please do help. Thanks in advance.

4 REPLIES 4

NeverTooOldToLe
New Contributor III

have you tried a mapper with javascript such as outlined here:

or perhaps the structure snap?

tstack
Former Employee

The extend() method can be used to create objects dynamically from other objects passed in as arguments. In your case, it looks like the objects in the ‘$Array’ field do not have overlapping keys, so you can directly use the array as the arguments to extend. However, you cannot just pass ‘$Array’ to extend(), you need to use the spread operator to indicate that the elements of the array should be treated as the arguments to the function, like so:

{}.extend(...$Array)

The {} part just creates an empty object for us to call extend() on.

There are a few other examples of using the extend() method in the community, like this one.

abjoe
New Contributor II

Thanks a lot… It helped…