Problem with Change node and Jsonata

I recently upgraded to NR ver 4 latest version the other day. I note the Jsonata node is throwing errors and that is is under revision.

So I tried the change mode. I use one injection node to inject already jsonata reformatted json data into the dashboard 1 chart and all works ok.

I then use another injection node to inject the raw json data into a change node and use the Jsonata feature to reformat the data and send to the chart but it appears unable to reformat the data using as shown below.

If I do the same and use the same raw data as an example message within the change node it works fine in the internal test as shown below

This is a clear anomaly as I am using the same raw data.

Any help is welcome as internally it picks up the data but when parsed as a msg it cannot do same?

I have tried to search but cannot find a similar case?

It would be easier if you posted a small flow to demonstrate the issue.
Off the top of my head it sounds like the msg structure may not be exactly the same as your test data ?

I think not, please show us a debug of the raw data (expanded) please, as to me it looks like the data is different from the test data.

Thanks but there is not much to it. One injection node connected to a change node connected to a chart node.

The raw json parsed as an oject from the injection node (msg.payload) to the change node is the same raw json used in the Example message within the change node.

As you can see the data array (sample) has 24 records whereas the change node returns 0 records.

However, internally within the change node it parses the same json data and detects all the data records?

I also thought the same thing that the data being injected is incorrect.

This is the json data. This works fine within the change node but not when parsed from as json from an inject node. Hence logic is the parsed data format must be incorrect? But it reformats ok bar for the data? Very weird

  "xml": {
    "result": "SUCCESS",
    "meter": {
      "serial": 61110358,
      "id": "Main Incomer ; Emmaus Hospital ; Main Sub ; Emmaus",
      "profile": {
        "sample": [
          {
            "result": "SUCCESS",
            "date": "2020-07-30 00:30:00.000",
            "kVA": 156.29559167167832,
            "P1": 154.75,
            "P2": 0,
            "Q1": 21.926,
            "Q2": 0,
            "Q3": 0,
            "Q4": 0,
            "STATUS": 0
          },
          {
            "result": "SUCCESS",
            "date": "2020-07-30 01:00:00.000",
            "kVA": 156.8087206248428,
            "P1": 154.18,
            "P2": 0,
            "Q1": 28.592,
            "Q2": 0,
            "Q3": 0,
            "Q4": 0,
            "STATUS": 0
          },
          {
            "result": "SUCCESS",
            "date": "2020-07-30 01:30:00.000",
            "kVA": 150.0659554862461,
            "P1": 147.55,
            "P2": 0,
            "Q1": 27.364,
            "Q2": 0,
            "Q3": 0,
            "Q4": 0,
            "STATUS": 0
          },
          {
            "result": "SUCCESS",
            "date": "2020-07-30 12:00:00.000",
            "kVA": 263.77821047994087,
            "P1": 261.84,
            "P2": 0,
            "Q1": 31.918,
            "Q2": 0,
            "Q3": 0,
            "Q4": 0,
            "STATUS": 0
          }
        ]
      }
    }
  }
}```

As we expected the test data is based in xml and the inject data is based in payload
your test data should be

{
    "payload": {
        "xml":{
             .........
        }
    }
}

Or your inject should be msg. xml, then remove the xml property from the json data.

1 Like

Nope it is not in xml.

The original meter data is in xml but it has been converted to json

The xml is just a path variable and can be set to anything.

This same data worked fine using xml2json and then json to reformat from string to object then Jsonata node but which now throws errors.

It does appear to be a small error somewhere but has me stumped?

Then set the inject to msg.xml and remove the xml from the json.

Again the test data does not reflect your inject node.

We asked for a example flow and the debug view supply them if you require an example to show the issue that i have identified to you.

Thank you.

It was really stupid as I suspected and you correctly noted :joy:.

Nothing wrong, just had to add "payload" to the filter path as you correctly noted.

The old junk in junk out adage

[{'series' : ["P","Q","S"],

 'data' : [
           [ $$.payload.xml.meter.profile.sample.{"x":$replace(date," ","T"), "y":$number(P1)/2} ],
           [ $$.payload.xml.meter.profile.sample.{"x":$replace(date," ","T"), "y":$number(Q1)/2} ],
           [ $$.payload.xml.meter.profile.sample.{"x":$replace(date," ","T"), "y":$number(kVA)}  ]
          ], 

"labels" : [""] }]Problem with Change node and Jsonata - #8 by gdiana

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.