Parsing http get response where the key value includes a space


#1

1) Give a description of the problem
An HTTP get response includes spaces in the key value field. I am unable to write a ‘set variable’ expression to match the key field to then directly extract the value.

A working example of this approach where the response does not contain a space is:
[obs:[air_temperature]]
With an expression of: {($response.obs.air_temperature)}

Here is the problematic response structure:
[Global:[AB CDE:value]]
The key is “AB CDE”, so includes a space between B and C.

I could use indexof and replace to pull the required value, but this would take multiple steps.
I tried placing quotes around the key value but this just errors.

2) What is the expected behaviour?
Is there a way to parse the reponse directly using the key value ?

3) What is happening/not happening?
Because the response includes spaces my expression errors.

4) Post a Green Snapshot of the pistonimage
Can be provided if needed?


#2

I haven’t tried it in a while but I believe we had to use $replace($response," “,”_") or some other character so we’re able to parse data keys with space in it. Set that new value into a variable then parse that.


#3

Note that @eibyer meant the function replace (not $replace). Also, if your values include spaces, this will also change those. I think you will need a regex for your search string if you don’t want to replace spaces in your values. I’m not good at those but might be something like:

replace($response,"/*(\s)*:/","_")

For documentation on replace, see https://wiki.webcore.co/Functions#replace

EDIT: One other question. Did you try escaping the space? i.e., “AB\ CDE”. or “AB%20CDE”