Parsing pump JSON data into variables?


#1

Hi all, I’m trying to wrap my head around how to pull individual values out of some parsed Jason which I’m getting from a node-js pool controller running on a Rasberry Pi. I’ve looked at some of the other topics and tried my way in the evaluation console to get anything out, yet no luck so far.

This is what the json looks like in Firefox/raw/prettyprint:
(If you’re wondering what the “1” is for in the 3rd line, it’s the pump number, as the pool controller supports multiple pump units)

{
“pump”: {
“1”: {
“pump”: 1,
“name”: “Pump 1”,
“type”: “VS”,
“time”: “9:55 PM”,
“run”: 4,
“mode”: 0,
“drivestate”: 0,
“watts”: 0,
“rpm”: 0,
“gpm”: 0,
“ppc”: 0,
“err”: 0,
“timer”: 0,
“duration”: 0,
“currentrunning”: {
“mode”: “off”,
“value”: 0,
“remainingduration”: -1
},
“externalProgram”: {
“1”: 750,
“2”: 1500,
“3”: 2900,
“4”: 3450
},
“remotecontrol”: 1,
“power”: 0,
“friendlyName”: “Pump 1”,
“virtualController”: “enabled”,
“currentprogram”: 0
}
}
}

I read somewhere that one need to escape the curly brackets, so I did that with this fugly hack:

p2

which yields this:

So this is the essence of the piston, i can post it yet it doesn’t really say much more than what’s below:

Make a GET request to (my url)
Set variable {pumpData} = {$response}
Set variable {parsable_variable} = replace({pumpData}, hacky string from above)
Do parse Json data {parseable_variable}

So if I understand it right, my parsable_variable here should now be, well - parsable?

I’ve tried all sorts of things I’ve found in the forums, yet I can’t seem to nail down the right incantation to pull out the values? Some of my fails:

set variable time = parsable_variable.pump.1.time
set variable time = parsable_variable.pump.[0].pump.[0].1.[0]
array item??

I’d be really happy if someone could kick me in the right direction and show me the correct syntax for an expression to pull out individual values from the structure above.

Thanks!


#2

I’m not at a computer but try $response.pump.1.time


#3

Sorry, that unfortunately does not yield the desired result. I’ve tried your suggestion, yet it seems no matter what I put after $response, it comes back as blank when I evaluate it, oddly enough.

$response.pump.1.time »»» (dynamic)
$response.randomblahdiblah »»» (dynamic)

Am I referencing it correctly?
Is it only the system variable $response which has the ability to reference the Json file’s structure with dot notation?

PS: In the interim, I bodged together this truely horrific piece of string-wrangling code which manages to pull the watts out:

mid(pumpData,indexof(pumpData,“watts”)+(length(“watts”)+2),indexof(right(pumpData,length(pumpData)-indexof(pumpData,“watts”)-(length(“watts”)+2)),","))

however that can’t be right that I’ll need that to get the values out?


#4

My test…

image

image

$response is only good during that one webcall, it doesn’t get saved unless you store in a variable. You won’t be able to test with the evaluation console.


#5

Aha! That was the issue. I was indeed storing the $result in one variable rather than multiple and then trying to parse and break out the fields of that variable. This works! I don’t even need that parse thing nor replace the curlybrackts. Nice!

Thanks for the help!