jsonjolt

Need a jolt spec which will get input as an array but will put only the first element of array in output, not the whole array


In input json "daysRanges" is an array which contains multiple value of "min" & "max". but in output I need only the first value of "min" & "max". Need a jolt spec which will transform this input json to output json.

Input json:

{
  "group": [
    {
      "daysRanges": [
        {
          "min": 0,
          "max": 0
        },
        {
          "min": 1,
          "max": 1
        }
      ]
    }
  ]
}

Output json:

{
  "group": [
    {
      "min": 0,
      "max": 0
    }
  ]
}

Solution

  • What you need is the element of index 0 such as

    [
      {
        "operation": "shift",
        "spec": {
          "group": {
            "*": {
              "daysRanges": {
                "0": {
                  "*": "&4[&1].&"//&4 represents going 4 levels up and replicating 
                                 //the value there, eg."group"
                                 //[&1] stands for the indexes of the innermost array
                                 //the rightmost & is for leaf node
                }
              }
            }
          }
        }
      }
    ]
    

    the demo on the site Jolt Transform Demo Using v0.1.1 is :

    Jolt Transform Demo