How to store JSON data in a variable?

What is the trick to storing JSON data (below) to a variable?

[{"_id":"634f61387a30e070d77d7289","device":"xDrip-SHFollower","date":1666146595000,"dateString":"2022-10-19T02:29:55.000Z","sgv":135,"delta":-7,"direction":"FortyFiveDown","type":"sgv","filtered":0,"unfiltered":0,"rssi":100,"noise":1,"sysTime":"2022-10-19T02:29:55.000Z","utcOffset":-240,"mills":1666146595000}]

Essentially I would like to separate out a few of those data points to their own variables (sgv, direction..)

Variable type is string.
I've tried both Set Variable From POST and Set Variable From GET..

Thanks.

2 Likes

I have also seen issues in storing HTTP results in a variable.

Another option would be to write a small driver or app, depending on your skill / appetite for that... Though I can understand for something so simple, it would be nice to use the built in options.

1 Like

Suspect that your JSON string may be too long. 312 vs ~254ish

When I get a json string from an API I usually parse it and store it as a map and use it from there. Take a look at the parseJson method in the docs.

Hopefully this is what you are looking for.

2 Likes

By that you mean there is a 255 character limit on string var's? So a file might be a preferable option, still accessible via a variable reference.

Correct.

1 Like

I think the limits have been extended recently, I created this app / driver has stored a JSON string of with the device configs. Below are some usage examples:

Variable

Decode / Usage

2 Likes

When you exceed 255 characters in a hub variable:

If you want to store them in state you can go pretty large.... Original question was about variables.

Thanks!
Using a local file will be fine. What's the trick to writing the request to a file? I don't see a simple option like with variables.

2 Likes

See: File Manager | Hubitat Documentation

2 Likes

For a driver or app there is a library that I created:

https://raw.githubusercontent.com/thebearmay/hubitat/main/libraries/localFileMethods.groovy

3 Likes

Download the Hubitat app