3

I have the input raw JSON file like this below:

[
  {
    "itemId": "001",
    "region": "North",
    "cume": [
      150,
      200,
      300,
      360
    ],
    "type": [
      "total",
      "app",
      "web",
      "registered"
    ]
  },
  {
    "itemId": "002",
    "region": "South",
    "cume": [
      1000,
      1200,
      3500,
      6200
    ],
    "type": [
      "total",
      "app",
      "web",
      "registered"
    ]
  }
]

And my expected output is:

[
  {
    "cume": 150,
    "region": "North",
    "type": "total"
  },
  {
    "cume": 200,
    "region": "North",
    "type": "app"
  },
  {
    "cume": 300,
    "region": "North",
    "type": "web"
  },
  {
    "cume": 360,
    "region": "North",
    "type": "registered"
  },
  {
    "cume": 1000,
    "region": "South",
    "type": "total"
  },
  {
    "cume": 1200,
    "region": "South",
    "type": "app"
  },
  {
    "cume": 3500,
    "region": "South",
    "type": "web"
  },
  {
    "cume": 6200,
    "region": "South",
    "type": "registered"
  }
]

What I have tried is below (it's not working)

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*s": {
          "*": {
            "@": "[&1].&(2,1)", 
            "@(2,region)": "[&1].region"
          }
        }
      }
    }
  }
]

My current output converts everything into a single list. For example, for the region field, the output has four items inside instead of a single item.

Mohammadreza Khedri
  • 2,523
  • 1
  • 11
  • 22
ysh_115
  • 33
  • 4

1 Answers1

1

This is your jolt spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "cume": {
          "*": {
            "@": "[&3][&1].&2",
            "@(2,region)": "[&3][&1].region",
            "@(2,type[&])": "[&3][&1].type"
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": ""
      }
    }
  }
]
Mohammadreza Khedri
  • 2,523
  • 1
  • 11
  • 22