cancel
Showing results for 
Search instead for 
Did you mean: 

I wanted to create multiple arrays from a single array based on specific Field

patan
New Contributor III

I have the below input:

“AT_Pricehash”:

		[
			{
				"@TermsListID": "Test1",
				"ORGID":"1000",
				"@MinimumQuantity": 1
			},
			{
				"@TermsListID": "Test2",
				"ORGID":"1001",
				"@MinimumQuantity": 1
			},
			{
				"@TermsListID": "Test3",
				"ORGID":"1000",
				"@MinimumQuantity": "1"
			}
		]

I wanted to generate two arrays based on the ORGID, expected output as below:

		"1000Array" : [
			{
				"@TermsListID": "Test1",
				"ORGID":"1000",
				"@MinimumQuantity": 1
			},
			{
				"@TermsListID": "Test3",
				"ORGID":"1000",
				"@MinimumQuantity": "1"
			}
		]

		"1001Array"[
			{
				"@TermsListID": "Test2",
				"ORGID":"1001",
				"@MinimumQuantity": 1
			}
		]

Since this requirement is part of the ultra pipeline, I cannot use the straightforaward way i.e. by using the Split, sort, and then perform the GroupBy Field snap to generate arrays based on ORGID.

We can use the child pipeline but I would like to see if we can get this done in the same pipeline directly.

Is there any way to achieve this such as a direct expression or expression library, etc?

Any help would be appreacited.

1 ACCEPTED SOLUTION

viktor_n
Contributor II

Hi @patan,

If you have already array you can achieve this with group_by function in jsonPath.

Like this: jsonPath($, "$array[*].group_by(value['ORGID'])")

And here is the output:
image

Regards,
Viktor

View solution in original post

2 REPLIES 2

viktor_n
Contributor II

Hi @patan,

If you have already array you can achieve this with group_by function in jsonPath.

Like this: jsonPath($, "$array[*].group_by(value['ORGID'])")

And here is the output:
image

Regards,
Viktor

patan
New Contributor III

Thank you @viktor_n it worked.