calling outside object property or parent

 https://try.jsonata.org/dxPC5s-zM

{
"list1": [
{
"b": 1,
"list2": [
{
"a": 1
},
{
"a": 2
},
{
"a": 3
}
]
},
{
"b": 2,
"list2": [
{
"a": 1
},
{
"a": 2
},
{
"a": 3
}
]
},
{
"b": 3,
"list2": [
{
"a": 1
},
{
"a": 2
},
{
"a": 3
}
]
}
]
}



{
"result": $$.list1.(
$b := b; /* temp var. */
{
"v": list2[a=$b].{
"v":a
}
})
}

Jsonata Date to milliseconds convertion


https://try.jsonata.org/r0q7GnSOh



lstData.strValue.$toMillis($, '[Y]-[M]-[D]')
{
"lstData": [
{
"strFieldName":"ActivityDate",
"strValue": "2020-06-28",
"dateTimeStamp": 1594857600000
},
{
"strFieldName":"ActivityDate",
"strValue": "2020-07-10",
"dateTimeStamp": 1595116800000
},
{
"strFieldName":"ActivityDate",
"strValue": "2020-07-25",
"dateTimeStamp": 1595289600000
}
]
}

retreiving data with a name that contains spaces or special charecters with Jsonata

 

{
"normal": 1,
"has some spaces": 2,
"@": 3
} Query: $."@" 2. `@`

delete the first element from an array while assuring the result is still an array in jsonata?

 


https://try.jsonata.org/BaO2T7_9i




retriving data greater than particular vvalue



https://try.jsonata.org/0vfDXqv4m


 

How to group the JSON object by a key using JSONata

 I want to use JSONata to do the grouping of json objects in an array based on a key within the JSON object.

For example, I want to group the cars based on their names for the JSON example given below.

[
  {
    "car" : "audi",
    "color" : "blue",
    "reg" : 133434
  },
   {
    "car" : "benz",
    "color" : "red",
    "reg" : 134444
  },
   {
    "car" : "audi",
    "color" : "red",
    "reg" : 134884
  }
]

Expected output

{
  "audi" : [
    {
    "car" : "audi",
    "color" : "blue",
    "reg" : 133434
    },
    {
    "car" : "audi",
    "color" : "red",
    "reg" : 134884
    }
  ],
  "benz" : [
    {
    "car" : "benz",
    "color" : "red",
    "reg" : 134444
    }
   ]
}

$${car: [$.{"car": car, "color": color, "reg": reg}]}



Avg KPI: To get average of array object property

 {"payload":[

{"name": "product1", "price": 100},
{"name": "product2", "price": 25},
{"name": "product1", "price": 50},
{"name": "product2", "price": 75},
{"name": "product3", "price": 25}
]}
payload{name:$average(price)} ~> $each(function($v, $n) {{
'name': $n,
'avg': $v
}}) ^(avg) //this is for ascending/descending order


calling outside object property or parent

 https://try.jsonata.org/dxPC5s-zM { "list1" : [ { "b" : 1 , "list2" : [ { ...