-1

I hava a json input and expected output is below. please help me in generating the spec.

Input JSON:

{  
    "Features": [    
      "fields": [
        {
          "name": "featureName"
        },
        {
          "name": "featureVersion"
        },
        {
          "name": "featureLevel"
        },
        {
          "name": "featureComponent"
        }
      ],
      "rows": [
        [
          "checkoutandopeninnative",
          "11R1",
          "1.0.0",
          "CheckoutAndOpenInNative",
          "1.0"
        ],
        [
          "ConfigurationMigration",
          "1.0",
          "1.0.1.68",
          "ConfigMigrationUtility",
          "1.0"
        ]
      ]
    ]    
}

Expected Output JSON:

 {
      "Features": [
        {
          "featureName": "checkoutandopeninnative",
          "featureVersion": "11R1",
          "featureLevel": "1.0.0",
          "featureComponent": "CheckoutAndOpenInNative"
        },
        {
          "featureName": "ConfigurationMigration",
          "featureVersion": "1.0",
          "featureLevel": "1.0.1.68",
          "featureComponent": "ConfigMigrationUtility"
        }
      ]
}

please help me with the spec to convert it in jolt. Am very new to jolt and few tried didnt work.

Thanks, Hari

  • Syntax: Consecutive square brackets [[[ are wrong, when deepening the structure; these should be interlayed by curly brackets: [{[{[ .. Your input file is wrong. Just see the output exaple, you stated yourself: It follows the rule. – Franta Dec 16 '20 at 19:25

2 Answers2

1

This spec should work for you:

[
  {
    "operation": "shift",
    "spec": {
      "Features": {
        "rows": {
          "*": {
            "*": "Features[&1].@(3,fields[&].name)"
          }
        }
      }
    }
  }
]

Notes:

  • I assume your input should look more like: "Features" : { ... } not "Features": [] as pointed out by @Franta
  • Checkout the https://jolt-demo.appspot.com/ where you can find the examples of the operators used in the snippet above
  • Also checkout the shiftr docs where you can find more info about the *, & and @ operators and their advanced versions

To make it easier to understand while reading the docs: shift operation explanation

kasptom
  • 2,363
  • 2
  • 16
  • 20
0

Seriously, no googling?

Seriously, a sequence of [[[ ? Try i.e. this validator: codebeautify.org/jsonviewer

So: Invalid JSON input. The validator says: E2 ->Error: Parse error on line 1: Parse error on line ^ Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'

The result:

Parse error on line 3: ...
"fields": [
{

----------------------^
Expecting 'EOF', '}', ',', ']', got ':'

Mistake in the syntax in the input: Consecutive square brackets [[[ are wrong, when deepening the structure; these should be interlayed by curly brackets: [{[{[

Just see the output example, you stated yourself: It follows the rule.

Franta
  • 986
  • 10
  • 17