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

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.

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

1 Like

Thank you @viktor_n it worked.