Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Blockly attributs in JSON show NULL #1647

Open
3 tasks done
Chris87-ux opened this issue Jul 23, 2024 · 5 comments
Open
3 tasks done

[Bug]: Blockly attributs in JSON show NULL #1647

Chris87-ux opened this issue Jul 23, 2024 · 5 comments

Comments

@Chris87-ux
Copy link

I'm sure that

  • This issue is still present in the current beta version of this adapter
  • There is no other (open) issue with the same topic (use the search!)
  • This issue is not described in the adapter documentation / FAQ (read the docs!)

Script type

Blockly

The problem

I have a JSON with various attributes, some of them can be read out with the blocky function, otheronce cant.
image
I asked the question of Facebook already and a other user confirmed, that its a issue of the getAttr(). On use of JSON.parse() with [" "] it is working.

iobroker.current.log (in debug mode!)

No response

Version of nodejs

18.17.1

Version of ioBroker js-controller

5.0.19

Version of adapter

8.3.1

@klein0r
Copy link
Collaborator

klein0r commented Jul 23, 2024

Okay that's an edge case. You can use JSONata to get that Attribute.

position.altitute is a path in an object like

{
  "position": {
    "altitude": 1234
  }
}

But your attribute is named position.altitute like:

{
  "position.altitude": 1234
}

@klein0r
Copy link
Collaborator

klein0r commented Jul 23, 2024

This is not easy to implement. e.g.

{
  "bla": {
    "geo.position": {
      "altitude": 1234
    }
  }
}

What is the path? bla.geo.position.altitude ? Maybe we should implement the default JavaScript syntax:

bla['geo.position'].altitude

@Chris87-ux
Copy link
Author

Thanks very much, this is the actual Json which I get from the Server:
image
Its an Array of these JSONs, in general I'm only interested on the last one (actual one).

@klein0r
Copy link
Collaborator

klein0r commented Jul 23, 2024

The structure of the response is not very common:

"position.altitude": 471,
"position.direction": 323,
"position.hdop": 1.6,
"position.latitude": 48.48151,
"position.longitude": 11.236118,
"position.pdop": 1.9,
"position satellites": 8,
"position.speed": 0,
"position.valid": true,

Should be:

"position": {
  "altitude": 471,
  "direction": 323,
  "hdop": 1.6,
  "latitude": 48.48151,
  "longitude": 11.236118,
  "pdop": 1.9,
  "satellites": 8,
  "speed": 0,
  "valid": true
}

Please use JSONata in Blockly to extract the information

@Chris87-ux
Copy link
Author

Fully aggree with you, as it seems they convert it from a mqtt interface.
How would look the argument than for my first example? https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/de/blockly.md#convert-by-jsonata-expression

If I don't split the JSON and I would like to use the last information:
Result[-1].["position.latitude"] ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants