[APP][Pro] JSON Handler and Manipulator

I was under the impression that should be added automatically by the app. However, I had tried it (I tried all permutations I could think of), but I am still just getting 0.

Could you recreate my flow cards and check if it is working for you? For me it just refuses to work. No errors, it just always spits out 0.

You should not add […] and “…” in Read-JSON-card.
Only type Total volume in the property path number 1 field.

I’ve tried that, of course. It still doesn’t work for me (# Number 1 becomes 0):

Please try the exact same and tell me if it works for you.

Seems you may not use space in the property path.
Use Totalvolume instead. Works for me.

The received JSON that I am wanting to parse does contain spaces in the key names, which is perfectly valid JSON. I would therefore strongly argue that this is a bug in the app.

Could you confirm, @Arie_J_Godschalk ?

Yes, you should be able to use spaces indeed.
I am trying to see why its not working as expected.

One moment please.

Okay, update to version 1.2.9 and its resolved.
What already would have resolved is, was placing a $ in front of the bracket, without the dot (my bad).

By default, the $. was placed in front of it, if a user didn’t do that. That caused the “bug”.

But i have changed it to include only a $ if it starts with a bracket.

Also, i have created a small script to see if only one property name is entered and if it contains non-ascii - non-word characters, and if so, place it within brackets.
This means you can now enter the name without using brackets, which makes the card more readable:

1 Like

Thanks for the quick update. I can confirm that it is working for me now. However, before I updated, I tested what you said about using just $ in front of the bracket would also resolve it, but that didn’t work for me (and I had tried that also previously).

It doesn’t matter now though, since the latest version does fix the problem. :+1:

One very minor thing that you might want to fix for the next version is that in the loop action card, you have “Loopnaam” instead of “Loop name” also when the Homey uses English as the language.

image

Hi there,
I am trying to parse a result from openweather.com, and unfortunately I need to find a way to handelt more than 10 numeric results (14 at least, to be precise).

Unfotunatly, JSONhandler throws an exception when trying to convince it to treat a returned numeric value as a string instead of a number… (my initial idea was to convert the string to a number later on)

What would be the easiest way to achieve the goal?

An example JSON output is:
{“lat”:53.587,“lon”:9.7634,“timezone”:“Europe/Berlin”,“timezone_offset”:7200,“current”:{“dt”:1712815812,“sunrise”:1712809759,“sunset”:1712859243,“temp”:10.87,“feels_like”:9.84,“pressure”:1026,“humidity”:70,“dew_point”:5.62,“uvi”:0.12,“clouds”:100,“visibility”:10000,“wind_speed”:6.17,“wind_deg”:210,“weather”:[{“id”:500,“main”:“Rain”,“description”:“Leichter Regen”,“icon”:“10d”}],“rain”:{“1h”:0.18}},“daily”:[{“dt”:1712833200,“sunrise”:1712809759,“sunset”:1712859243,“moonrise”:1712812500,“moonset”:0,“moon_phase”:0.1,“summary”:“Expect a day of partly cloudy with rain”,“temp”:{“day”:10.13,“min”:7.29,“max”:12.35,“night”:11.68,“eve”:12.12,“morn”:10.59},“feels_like”:{“day”:9.57,“night”:11.46,“eve”:11.84,“morn”:9.51},“pressure”:1028,“humidity”:91,“dew_point”:8.76,“wind_speed”:6.38,“wind_deg”:211,“wind_gust”:15.98,“weather”:[{“id”:501,“main”:“Rain”,“description”:“Mäßiger Regen”,“icon”:“10d”}],“clouds”:100,“pop”:1,“rain”:2.33,“uvi”:0.76},{“dt”:1712919600,“sunrise”:1712896018,“sunset”:1712945752,“moonrise”:1712900460,“moonset”:1712875680,“moon_phase”:0.14,“summary”:“There will be partly cloudy today”,“temp”:{“day”:14.39,“min”:9.95,“max”:16.41,“night”:9.95,“eve”:14.19,“morn”:11.42},“feels_like”:{“day”:14.16,“night”:8.83,“eve”:13.75,“morn”:11.12},“pressure”:1027,“humidity”:87,“dew_point”:12.19,“wind_speed”:6.33,“wind_deg”:234,“wind_gust”:11.86,“weather”:[{“id”:804,“main”:“Clouds”,“description”:“Bedeckt”,“icon”:“04d”}],“clouds”:100,“pop”:0,“uvi”:3.33},{“dt”:1713006000,“sunrise”:1712982278,“sunset”:1713032262,“moonrise”:1712989140,“moonset”:1712967120,“moon_phase”:0.17,“summary”:“Expect a day of partly cloudy with rain”,“temp”:{“day”:17.25,“min”:8.93,“max”:18.04,“night”:15.85,“eve”:16.44,“morn”:10.26},“feels_like”:{“day”:16.83,“night”:15.66,“eve”:16.23,“morn”:9.8},“pressure”:1023,“humidity”:69,“dew_point”:11.45,“wind_speed”:6.37,“wind_deg”:251,“wind_gust”:14.93,“weather”:[{“id”:500,“main”:“Rain”,“description”:“Leichter Regen”,“icon”:“10d”}],“clouds”:100,“pop”:0.2,“rain”:0.13,“uvi”:3.78},{“dt”:1713092400,“sunrise”:1713068539,“sunset”:1713118772,“moonrise”:1713078900,“moonset”:1713057480,“moon_phase”:0.21,“summary”:“Expect a day of partly cloudy with rain”,“temp”:{“day”:11.68,“min”:5.81,“max”:15.6,“night”:5.81,“eve”:7.76,“morn”:9.37},“feels_like”:{“day”:10.34,“night”:2.84,“eve”:4.42,“morn”:6.09},“pressure”:1018,“humidity”:55,“dew_point”:2.94,“wind_speed”:8.52,“wind_deg”:279,“wind_gust”:15.85,“weather”:[{“id”:500,“main”:“Rain”,“description”:“Leichter Regen”,“icon”:“10d”}],“clouds”:64,“pop”:0.42,“rain”:0.67,“uvi”:3.57},{“dt”:1713178800,“sunrise”:1713154800,“sunset”:1713205282,“moonrise”:1713169440,“moonset”:1713146580,“moon_phase”:0.25,“summary”:“The day will start with partly cloudy through the late morning hours, transitioning to rain”,“temp”:{“day”:10.44,“min”:3.92,“max”:10.44,“night”:3.92,“eve”:6.03,“morn”:6.36},“feels_like”:{“day”:9.29,“night”:-0.65,“eve”:2.5,“morn”:3.78},“pressure”:1005,“humidity”:67,“dew_point”:4.66,“wind_speed”:7.1,“wind_deg”:233,“wind_gust”:11.98,“weather”:[{“id”:501,“main”:“Rain”,“description”:“Mäßiger Regen”,“icon”:“10d”}],“clouds”:88,“pop”:1,“rain”:7.76,“uvi”:2.71},{“dt”:1713265200,“sunrise”:1713241062,“sunset”:1713291792,“moonrise”:1713260460,“moonset”:1713234720,“moon_phase”:0.27,“summary”:“You can expect rain in the morning, with partly cloudy in the afternoon”,“temp”:{“day”:8.3,“min”:2.77,“max”:8.69,“night”:4.52,“eve”:6.12,“morn”:4.94},“feels_like”:{“day”:4.71,“night”:1.78,“eve”:2.95,“morn”:0.34},“pressure”:1003,“humidity”:78,“dew_point”:4.81,“wind_speed”:7.6,“wind_deg”:275,“wind_gust”:14.34,“weather”:[{“id”:501,“main”:“Rain”,“description”:“Mäßiger Regen”,“icon”:“10d”}],“clouds”:99,“pop”:1,“rain”:16.93,“uvi”:3},{“dt”:1713351600,“sunrise”:1713327325,“sunset”:1713378302,“moonrise”:1713351600,“moonset”:1713322320,“moon_phase”:0.3,“summary”:“Expect a day of partly cloudy with rain”,“temp”:{“day”:8.32,“min”:2.02,“max”:8.32,“night”:2.02,“eve”:5.28,“morn”:4.86},“feels_like”:{“day”:4.64,“night”:-0.86,“eve”:1.56,“morn”:1.56},“pressure”:1013,“humidity”:69,“dew_point”:2.92,“wind_speed”:7.48,“wind_deg”:300,“wind_gust”:10.56,“weather”:[{“id”:500,“main”:“Rain”,“description”:“Leichter Regen”,“icon”:“10d”}],“clouds”:81,“pop”:1,“rain”:2.28,“uvi”:3},{“dt”:1713438000,“sunrise”:1713413588,“sunset”:1713464812,“moonrise”:1713442560,“moonset”:1713409500,“moon_phase”:0.33,“summary”:“Expect a day of partly cloudy with rain”,“temp”:{“day”:9.06,“min”:0.61,“max”:9.06,“night”:2.11,“eve”:5.53,“morn”:3.21},“feels_like”:{“day”:7.03,“night”:-0.23,“eve”:2.67,“morn”:1.85},“pressure”:1014,“humidity”:62,“dew_point”:2.18,“wind_speed”:4.69,“wind_deg”:322,“wind_gust”:8.31,“weather”:[{“id”:500,“main”:“Rain”,“description”:“Leichter Regen”,“icon”:“10d”}],“clouds”:74,“pop”:1,“rain”:2.73,“uvi”:3}]}

Specifically, text3 is failing (as would text 4,5, and 6)…

Regards

Just use 2 flowcards if you have more then 10 results.

1 Like

how embarrassing… thanks!

Follow-Up question:
Apparently, one JSON-field is optional (“snow”), i.e. it is only returned if it will actually snow. If empty, an exception is thrown (so far so good), but the other fields aren´t read, either…

I would use another flowcard for any optional fields.
So that flowcard(s) can generate an error if empty, but the mandatory flowcard still finishes correctly.

1 Like

Is there any documentation that describes the basics a little more?
To be honest, I’m a bit confused by the posts here in the forum.
What should be done with the flowcards and with HomeScript?
And why?
Where and how should or can foreign JSON be inserted and parsed?

You do not need HomeyScript at all.

Say you receive a json string with the card “Start flow with text”.
The string might look like {“Item”:“Car”,“Wheels”:4}.
User the json parse card, enter “Item” in “Property path text 1” and “Wheels” in “Property path number 1” to retrieve the values.

1 Like

Hi Arie,

I have a question.

I’m sending some variables within JSON from my laptop using Curl. One of the values should be a Boolean and is defined in the JSON as true or false. Not as 0 or 1. The JSON is received by Homey and looks like this:

{“PowerState”:“On”,“ChargerState”:2,“ChargeRemaining”:89,“InHouseLocation”:“Achter Zolder”,“Username”:“Dennis van Dinter”,“UserLockState”:“Unlocked”,“Test”:true}

When I use the JSON Handler app I use the Read JSON card and define the first yes/no-field as “Test”. But after receiving the JSON again nothing happens.

To send a Boolean within JSON, as far as I know I need to use lower cast without quotes. But I could be wrong. Do I need to use another value type?

@Dennis_van_Dinter
Hey Dennis,

Please place the json in a code block, so i can know for sure if its valid.

And show a screenshot of the Json Read card? To see if its being used correctly and to simulate it on my end.

Thanks

EDIT*

Never mind. I was looking with my nose. I also had a value in the expression field of the text field itself in the Device Capabilities app.

Hi Arie,

Got it to work after all. There was something wrong in the conversion from string to boolean.

That brings me to another question. One of the Boolean’s I’m sending as json is if wether or not the charger of the laptop is connected. What I want to do is to use that Boolean to set a value of a field of an advanced virtual device to a certain name. If true = Netstroom, if false = Accu.
For the virtual device I used the “Put textfield to BLL expression”-card.
Please see attached screen for your refference.

Any ideas if this is possible and how to do it?

EDIT

So I found out that when using the card like this when the yes/no field is ja/nee1, I can use the expression:

ja/nee1 ? ‘Netstroom’ : ‘Accu’

But for some reason when testing the flow or actually receiving the Boolean value I do see the value in the app changing for a split second, but reverting back to the value that was showing in the first place. I restarted the BLL app, the JSON Hanlder app and the Device Capabilities app,

The solution sounded so simple. I still managed to fail. Please, what am I doing wrong here? The lower part doesn’t work, the five values aren’t updated. The data in the json seems fine.


Thx

And if you try to set one of those flowcard by manualy "running " that card using the value from the json?

Is it not a difference of percentages or something like that?
Like setting it to 0.01 while the allowed values is between 1 and 100?

This make me a little confused now because I was thinking to understand this app.

There is 1 JSON file. “Message received from topic”.
That file have the same ‘construction’, I think.
How can you get for i.e. the ‘Number 1’ then 2 different values.
Because 1st Number is always 1st Number.

Otherwise var in “Number 1” from the smaller card is in “Yes/No 1” there. 10 ‘places’ lower.

Maybe I have starting to learn over again. :wink: