Create a Json from two seperate arrays Key and value

HI i have two arrays : 1.Name and 2. Values

Names = [
“key1”,“key2”,“key3”
]

Values = [
“Value1”,“Value2”,“Value3”
]

I want output from snap as

{“key1” : “value1”,
“key2” :“value2” …
}

Hi @ash42,

Do you want the output to be only one object?

If yes, then try with the following expression in a Mapper Snap:

$Names.reduce((acc,curr,ind) => acc.extend({[curr]: $Values[ind]}), {})

The output will look like this:

[
	{
		"key1": "Value1",
		"key2": "Value2",
		"key3": "Value3"
	}
]

Let me know if this is the desired output.

BR,
Aleksandar.

1 Like

Works for me ,Thank You

1 Like