0
votes

Input:

[
  {
    "name": "Foo",
    "ratings": [
      {
        "value": 2
      },
      {
        "value": 4
      }
    ]
  }
]

Spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "ratings": {
          "@": ""
        }
      }
    }
  }
]

Output:

[ {
  "value" : 2
}, {
  "value" : 4
} ]

What I want to achieve:

[ {
  "name": "Foo",
  "value" : 2
}, {
  "name": "Foo",
  "value" : 4
} ]

Any ideas how to modify my jolt spec to achieve that output?

1

1 Answers

0
votes
[
  {
    "operation": "shift",
    "spec": {
      "*": { // top level array
        "ratings": {
          "*": { // ratings array
            // push name down, but maintain the 
            //  same doubly nested array structure
            "@(2,name)": "[&3].[&1].name",
            // copy everything inside a ratings document 
            "*": "[&3].[&1].&"
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": { // top level array
        // 2nd level array
        "*": "[]"
      }
    }
  }
]