question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JOLT : Grouped as array while transforming the json

See original GitHub issue

Hello @milosimpson ,

I was trying to convert the json from one JSON Format to another JSON Format using JOLT, But i’m not able to get the expected output. I have included the my work around below. Any help will be appreciated. Thanks.

My input.json

{
    "Result": {
    },
    "Content": [
        {
            "MovieDetails": [
                {
                    "Key": "TicketNumber",
                    "Value": "DF-0001"
                },
                {
                    "Key": "MovieName",
                    "Value": "Test"
                }
            ]
        },
        {
            "MovieDetails": [
                {
                    "Key": "TicketNumber",
                    "Value": "DF-0002"
                },
                {
                    "Key": "MovieName",
                    "Value": "Test2"
                }
            ]
        },
        {
            "MovieDetails": [
                {
                    "Key": "TicketNumber",
                    "Value": "DF-0003"
                },
                {
                    "Key": "MovieName",
                    "Value": "Test3"
                }
            ]
        }
    ]
}

My Expected Output.json

{
"Result": {

},
"Content": [
    {
        "MovieDetails": {
            "TicketNumber": "DF-0001",
            "MovieName": "Test1"
        },
        "MovieDetails": {
            "TicketNumber": "DF-0002",
            "MovieName": "Test2"
        }.
        "MovieDetails": {
            "TicketNumber": "DF-0003",
            "MovieName": "Test3"
        }
    }
]
} 

My Actual Output.json

{
"Result": {

},
"Content": [
    {
        "MovieDetails": {
            "TicketNumber": ["DF-0001","DF-0002","DF-0003"],
            "MovieName": ["Test1","Test2","Test3"]
        }
    }
]
} 

My Spec.json

[
    {
        "operation": "shift",
        "spec": {
            "Result": {
                "*": "Result.&"
            },
            "Content": {
                "*": {
                    "MovieDetails": {
                        "*": {
                            "Value": "Content.MovieDetails.@(1,Key)"
                        }
                    }
                }
            }
        }
    }
]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
milosimpsoncommented, Sep 21, 2018

Spec

[
  {
    "operation": "shift",
    "spec": {
      "Result": "Result",
      "Content": {
        "*": {
          "MovieDetails": {
            "*": {
              // [&3] --> lookup the index from 4 levels up
              //   which is the "*" under Context
              "Value": "Content[&3].MovieDetails.@(1,Key)"
            }
          }
        }
      }
    }
  }
]
0reactions
ramuece09commented, Nov 1, 2018

Got null because of lower version. Changed version to 0.1.1 and works like a charm. You’re always a superhero @milosimpson

Read more comments on GitHub >

github_iconTop Results From Across the Web

JOLT - Transform Array of JSON objects containing nested ...
I want to transform a JSON input file into expected JSON output file: My input file: [ { "category": [ { "id": "id1",...
Read more >
Transformer - Getting to know JOLT | Digibee Help Center
Understanding transformations with JOLT and how to apply them. ... the function of grouping certain content of the input JSON within the list...
Read more >
jolt: JSON Transforms Simplified - chrisjordan.ca
Sometimes a property you want is an array when it has multiple values but an object when there is only one. It's annoying...
Read more >
Jolt transform nested json array - Cloudera Community - 354431
How can I break and flatten nested JSON with arrays using Jolt transformations from: { "product": [ - 354431.
Read more >
Nifi - Using Jolt Transform Json to prepare your Big Data
At some point everyone who works with data needs to work with json. Learn how to work with it in Apache Nifi in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found