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.

URGENT HELP on nested JOLT

See original GitHub issue

HI All,

Is there an easy way to capture object index ? INPUT: { "header": { "namespace": "someNamespace", "version": "1" }, "body": { "dataM": { "sourceM": [ { "name": "State", "type": "string" }, { "name": "City", "type": "string" }, { "name": "var", "type": "string" }, { "name": "unit", "type": "string" }, { "name": "type", "type": "string" } ], "valueM": [ { "name": "timestamp", "type": "date-time" }, { "name": "value", "type": "string" }, { "name": "quality", "type": "integer" }, { "name": "error", "type": "string" } ] }, "data": [ { "source": [ "Austria", "Vienna", "temp", "F", "now" ], "values": [ [ "2018-10-02T15:00:00.05Z", "3.1234", 7, "SomeError" ], [ "2018-10-02T15:00:46.05Z", "3.221", 0, "SomeOtherError" ] ] }, { "source": [ "Germany", "Berlin", "pressure", "PA", "now" ], "values": [ [ "2018-10-02T16:00:00.05Z", "5", 0, "NoError" ] ] } ] } }

spec: [{ "operation": "shift", "spec": { "body": { "data": { "*": { "@(4,header)": { "*": "newdata[&2].&" }, "source": { "*": "newdata.[&2].@(4,dataM.sourceM.[&].name)" }, "values": { "*": { "*": "newdata.[&3].@(5,dataM.valueM[&].name)" } } } } } } } , { "operation": "shift", "spec": { "newdata": { "*": "[&0]" } } } ]

Desired Output: [ { "namespace" : "someNamespace", "version" : "1", "State" : "Austria", "City" : "Vienna", "var" : "temp", "unit" : "F", "type" : "now", "timestamp" :"2018-10-02T15:00:00.05Z", "value" : "3.1234", "quality" : 7, "error" : "SomeError" }, { "namespace" : "someNamespace", "version" : "1", "State" : "Austria", "City" : "Vienna", "var" : "temp", "unit" : "F", "type" : "now", "timestamp" : "2018-10-02T15:00:46.05Z" , "value" : "3.221" , "quality" : 0, "error" : "" },{ "namespace" : "someNamespace", "version" : "1", "State" : "Germany", "City" : "Berlin", "var" : "pressure", "unit" : "PA", "type" : "now", "timestamp" : "2018-10-02T16:00:00.05Z", "value" : "5", "quality" : 0, "error" : "NoError" } ]

Currently, I’m getting arrays for timestamp, value, quality and error for each object. Instead, I need source array repeated per number of values within the data object.

@mattyb149 @milosimpson can anyone help? @niernier007 @theamitojha

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
theamitojhacommented, Jul 29, 2019

Seems like * is being removed while pasting it here please add left hand side.

[ { “operation”: “shift”, “spec”: { “body”: { “data”: { “": { “values”: { "”: { “@(5,header.namespace)”: “newdata.box.namespace”, “@(5,header.version)”: “newdata.box.version”, “@(2,source)”: { “": “newdata.box.@(6,dataM.sourceM.[&].name)” }, "”: “newdata.box.@(5,dataM.valueM.[&].name)” } } } } } } }, { “operation”: “shift”, “spec”: { “newdata”: { “box”: { “": { "”: “[&].&1” } } } } } ]

1reaction
MagdaToczekcommented, Aug 7, 2019

@nenyri, please check out if it is what you ment:

[
  {
    "operation": "shift",
    "spec": {
      "body": {
        "data": {
          "*": {
            "values": {
              "*": {
                "@(5,header.namespace)": "newdata.box.namespace[]",
                "@(5,header.version)": "newdata.box.version[]",
                "@(2,source)": {
                  "*": "newdata.box.@(6,dataM.sourceM.[&].name)[]"
                },
                "*": "newdata.box.@(5,dataM.valueM.[&].name)[]"
              }
            }
          }
        }
      }
    }
},
  {
    "operation": "shift",
    "spec": {
      "newdata": {
        "box": {
          "*": {
            "*": "[&].&1"
          }
        }
      }
    }
  }
]
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to read nested value using shift operation in JOLT
I am trying to read a nested value using shift operation. Basically the value of person is dynamic and based on this value,...
Read more >
Jolt Transformation Nested Json to Flat Json - 288874
Can somebody please help me correct my Jolt Spec to get the exact transformation I am looking for? I have really tried cracking...
Read more >
Apache NiFi: Having fun with Jolt transformations
You can only use an input source with many nested objects once in the same (shift) Jolt transformation. If you want to use...
Read more >
Simple IF - ELSE with JOLT | Digibee Help Center
Below, there is a simple way of settling this situation, only using a Transformer Connector. Transformation and "IF-ELSE" with JOLT: [ { "operation":...
Read more >
Jolt
A JAMstack architecture eliminates the need for manually adding and removing servers in order to scale your application, as is often required with...
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