cancel
Showing results for 
Search instead for 
Did you mean: 

transform a array

manohar
Contributor

Hi there, need some help transforming the array

I have a structure that's coming as below

[
  {
    "statusLine": {
      "protoVersion": "HTTP/1.1",
      "statusCode": 200,
      "reasonPhrase": "OK"
    },
    "entity": {
      "links": [
        {
          "rel": "self"
        }
      ],
      "items": [
        {
          "datetime_beginning_utc": "2023-01-01T00:00:00",
          "pnode_id": 1269364670,
          "total_lmp_rt": 25.611892,
          "marginal_loss_price_rt": 0.132546
        },
        {
          "datetime_beginning_utc": "2023-01-01T01:00:00",
          "pnode_id": 1269364670,
          "total_lmp_rt": 22.818414,
          "marginal_loss_price_rt": 0.150509
        }
      ]
    },
    "original": {
      "priceType": "rt_hrl_lmps",
      "pnodId": "1269364670",
    }
  }
]

 Need to be transformed as below with only from "items" and "original". Need to combine both while adding "original" to all array elements in "items".

 

Any help is greatly appreciated.

 

Thanks

Manohar

[
	{
		"datetime_beginning_utc": "2023-01-01T00:00:00",
		"pnode_id": 1269364670,
		"total_lmp_rt": 25.611892,
		"marginal_loss_price_rt": 0.132546,
		"priceType": "rt_hrl_lmps",
		"pnodId": "1269364670"
	},
	{
		"datetime_beginning_utc": "2023-01-01T01:00:00",
		"pnode_id": 1269364670,
		"total_lmp_rt": 22.818414,
		"marginal_loss_price_rt": 0.150509,
		"priceType": "rt_hrl_lmps",
		"pnodId": "1269364670"
	}
]

 

1 REPLY 1

alchemiz
Contributor III

Hi @manohar ,
Good day, try this expression $entity.get('items',[]).map(i=> i.merge($.get('original',{})))

alchemiz_0-1692727369756.png