cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Create a Json from two seperate arrays Key and value

ash42
New Contributor III

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โ€ โ€ฆ
}

1 ACCEPTED SOLUTION

AleksandarAngel
Contributor III

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.

View solution in original post

2 REPLIES 2

AleksandarAngel
Contributor III

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.

Works for me ,Thank You