0

I want to use Jolt to transform a JSON dataset. The problem is that my entire dataset is treated like an array because it is originally transformed from XML. Here is an example of the first 3 records:

{

    "XMLSOCCER.COM" : { "Team" :[{

    "Team_Id" : "45",
    "Name" : "Aberdeen",
    "Country" : "Scotland",
    "Stadium" : "Pittodrie Stadium",
    "HomePageURL" : "http://www.afc.co.uk",
    "WIKILink" : "http://en.wikipedia.org/wiki/Aberdeen_F.C.",
    "Capacity" : "20866",
    "Manager" : "Derek McInnes"
},{

    "Team_Id" : "46",
    "Name" : "St Johnstone",
    "Country" : "Scotland",
    "Stadium" : "McDiarmid Park",
    "HomePageURL" : "http://www.perthstjohnstonefc.co.uk",
    "WIKILink" : "http://en.wikipedia.org/wiki/St._Johnstone_F.C."
},{

    "Team_Id" : "47",
    "Name" : "Motherwell",
    "Country" : "Scotland",
    "Stadium" : "Fir Park Stadium",
    "HomePageURL" : "http://www.motherwellfc.co.uk",
    "WIKILink" : "http://en.wikipedia.org/wiki/Motherwell_F.C."
}}]}}

For a single record-set, I can use this spec which gives me the correct output:

[
{
"operation": "shift",
"spec": {
  "XMLSOCCER.COM": {
    "Team": {
      "Team_Id": "Team_Id",
      "Name": "Name",
      "Country": "Country",
      "Stadium": "Stadium",
      "Capacity": "Capacity",
      "Manager": "Manager"
    }
  }
}}]

But because my entire dataset is treated as a JSON array (an array under "Team"), I cannot figure out how to create the spec to work with this configuration. I appreciate any input. thanks!

1 Answer 1

1

Spec: Match into all the elements of the Team array, and then reference the element number of the team array for each key in the output.

[
  {
    "operation": "shift",
    "spec": {
      "XMLSOCCER.COM": {
        "Team": {
          "*": {
            "Team_Id": "soccer[&1].Team_Id",
            "Name": "soccer[&1].Name",
            "Country": "soccer[&1].Country",
            "Stadium": "soccer[&1].Stadium",
            "Capacity": "soccer[&1].Capacity",
            "Manager": "soccer[&1].Manager"
          }
        }
      }
    }
  }
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.