Skip to content

Getting value from a JSON point #3097

Answered by fabiodurao
a3pl1 asked this question in Q&A
Discussion options

You must be logged in to vote

Hello,

It is possible to do this conversion using a meta datapoint.

1 - First, create this mqtt datapoint that returns this json in string;
2 - Create a meta datasource and then a datapoint with the name "kitchen" for example;
3 - In this datapoint, set it as numeric, add the mqtt datapoint created in item 1, within the context and give it a nickname "kitchen";
4 - Use the following script to convert the string to json and return only the value;

const jsonString = kitchen.value;
const jsonObject = JSON.parse(jsonString); // Convert a string to JSON object

const valueAsNumber = Number(jsonObject.value);
return valueAsNumber; // Return 21 how number

5 - Click on the green circle to the le…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@a3pl1
Comment options

Answer selected by a3pl1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants