It is currently March 29th, 2024, 2:10 am

JSON Parsing

Get help with creating, editing & fixing problems with skins
takochako
Posts: 9
Joined: September 11th, 2017, 9:19 pm

JSON Parsing

Post by takochako »

I'm trying to parse the current temperature from Dark Sky (weather website) and can't seem to get it to work. Can someone please help?

This is an example of the format it's in.

Code: Select all

 {
              "latitude": 47.20296790272209,
              "longitude": -123.41670367098749,
              "timezone": "America/Los_Angeles",
              "currently": {
                "time": 1453402675,
                "summary": "Rain",
                "icon": "rain",
                "nearestStormDistance": 0,
                "precipIntensity": 0.1685,
                "precipIntensityError": 0.0067,
                "precipProbability": 1,
                "precipType": "rain",
                "temperature": 48.71,
                "apparentTemperature": 46.93,
                "dewPoint": 47.7,
                "humidity": 0.96,
                "windSpeed": 4.64,
                "windBearing": 186,
                "visibility": 4.3,
                "cloudCover": 0.73,
                "pressure": 1009.7,
                "ozone": 328.35
              },
              "minutely": {
                "summary": "Rain for the hour.",
                "icon": "rain",
                "data": [
                {
                  "time": 1453402620,
                  "precipIntensity": 0.1715,
                  "precipIntensityError": 0.0066,
                  "precipProbability": 1,
                  "precipType": "rain"
                },
                ...
                ]
              },
              "hourly": {
                "summary": "Rain throughout the day.",
                "icon": "rain",
                "data": [
                {
                  "time": 1453399200,
                  "summary": "Rain",
                  "icon": "rain",
                  "precipIntensity": 0.1379,
                  "precipProbability": 0.85,
                  "precipType": "rain",
                  "temperature": 48.16,
                  "apparentTemperature": 46.41,
                  "dewPoint": 46.89,
                  "humidity": 0.95,
                  "windSpeed": 4.47,
                  "windBearing": 166,
                  "visibility": 3.56,
                  "cloudCover": 0.39,
                  "pressure": 1009.97,
                  "ozone": 328.71
                },
                ...
                ]
              },
              "daily": {
                "summary": "Light rain throughout the week, with temperatures bottoming out at 48°F on Sunday.",
                "icon": "rain",
                "data": [
                {
                  "time": 1453363200,
                  "summary": "Rain throughout the day.",
                  "icon": "rain",
                  "sunriseTime": 1453391560,
                  "sunsetTime": 1453424361,
                  "moonPhase": 0.43,
                  "precipIntensity": 0.1134,
                  "precipIntensityMax": 0.1722,
                  "precipIntensityMaxTime": 1453392000,
                  "precipProbability": 0.87,
                  "precipType": "rain",
                  "temperatureMin": 41.42,
                  "temperatureMinTime": 1453363200,
                  "temperatureMax": 53.27,
                  "temperatureMaxTime": 1453417200,
                  "apparentTemperatureMin": 36.68,
                  "apparentTemperatureMinTime": 1453363200,
                  "apparentTemperatureMax": 53.27,
                  "apparentTemperatureMaxTime": 1453417200,
                  "dewPoint": 46.79,
                  "humidity": 0.95,
                  "windSpeed": 4.26,
                  "windBearing": 150,
                  "visibility": 4.02,
                  "cloudCover": 0.77,
                  "pressure": 1009.35,
                  "ozone": 326.69
                },
                ...
                ]
              },
              "alerts": [
              {
                "title": "Flood Watch for Mason, WA",
                "time": 1453375020,
                "expires": 1453407300,
                "description": "...FLOOD WATCH REMAINS IN EFFECT THROUGH LATE FRIDAY NIGHT...\nTHE FLOOD WATCH CONTINUES FOR\n* A PORTION OF NORTHWEST WASHINGTON...INCLUDING THE FOLLOWING\nCOUNTY...MASON.\n* THROUGH LATE FRIDAY NIGHT\n* A STRONG WARM FRONT WILL BRING HEAVY RAIN TO THE OLYMPICS\nTONIGHT THROUGH THURSDAY NIGHT. THE HEAVY RAIN WILL PUSH THE\nSKOKOMISH RIVER ABOVE FLOOD STAGE TODAY...AND MAJOR FLOODING IS\nPOSSIBLE.\n* A FLOOD WARNING IS IN EFFECT FOR THE SKOKOMISH RIVER. THE FLOOD\nWATCH REMAINS IN EFFECT FOR MASON COUNTY FOR THE POSSIBILITY OF\nAREAL FLOODING ASSOCIATED WITH A MAJOR FLOOD.\n",
                "uri": "http://alerts.weather.gov/cap/wwacapget.php?x=WA1255E4DB8494.FloodWatch.1255E4DCE35CWA.SEWFFASEW.38e78ec64613478bb70fc6ed9c87f6e6"
              },
              ...
              ],
              {
                "flags": {
                  "units": "us",
                  ...
                }
              }
User avatar
CyberTheWorm
Posts: 860
Joined: August 22nd, 2016, 11:32 pm
Location: Surrey, B.C., Canada

Re: JSON Parsing

Post by CyberTheWorm »

Code: Select all

[MeasureValues]
Measure=Plugin
Plugin=WebParser
URL=#WebSite#
RegExp=(?siU)<"temperature":>(.*)<,>

[Measure]
Measure=Plugin
Plugin=WebParser
URL=[MeasureValues]
StringIndex=1
Something like this
The only source of knowledge is experience. Albert Einstein
Deviant Art Page
takochako
Posts: 9
Joined: September 11th, 2017, 9:19 pm

Re: JSON Parsing

Post by takochako »

CyberTheWorm wrote:

Code: Select all

[MeasureValues]
Measure=Plugin
Plugin=WebParser
URL=#WebSite#
RegExp=(?siU)<"temperature":>(.*)<,>

[Measure]
Measure=Plugin
Plugin=WebParser
URL=[MeasureValues]
StringIndex=1
Something like this
Sadly, it didn't work. I think the problem is there are multiple values called "temperature" that are under different sections in the JSON feed. This is the result:
Image
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: JSON Parsing

Post by mak_kawa »

This RegExp works for me.

Code: Select all

[MeasureWP]
Measure=Plugin
Plugin=WebParser
URL=#URL#
RegExp=(?siU)"temperature":(.*),

[MeasureValue]
Measure=Plugin
Plugin=WebParser
URL=[MeasureWP]
StringIndex=1
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: JSON Parsing

Post by balala »

mak_kawa wrote:This RegExp works for me.
mak_kawa's RegExp indeed works well.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: JSON Parsing

Post by jsmorley »

I suspect that you are encoding your skin .ini file as UTF-8. If you have your skin .ini encoded as ANSI, and are pasting in the degree ° symbol, that can cause some text editors to save the file as UTF-8. Try encoding the skin using UTF-16 Little Endian, which would be just "Unicode" in Notepad, and "UCS-2 LE BOM" in Notepad++

https://docs.rainmeter.net/tips/unicode-in-rainmeter/

While WebParser assumes and wants UTF-8 as the remote source, Rainmeter itself HATES it when used as the encoding of the skin .ini file. As a general rule, .ini files should just always be encoded as UTF-16.

BTW, If you have the latest 4.1 beta version of Rainmeter, and why wouldn't you, this can also help in this case:

https://docs.rainmeter.net/manual-beta/variables/character-variables/

Hint: The degree ° symbol would be [\x00B0]
takochako
Posts: 9
Joined: September 11th, 2017, 9:19 pm

Re: JSON Parsing

Post by takochako »

mak_kawa wrote:This RegExp works for me.

Code: Select all

[MeasureWP]
Measure=Plugin
Plugin=WebParser
URL=#URL#
RegExp=(?siU)"temperature":(.*),

[MeasureValue]
Measure=Plugin
Plugin=WebParser
URL=[MeasureWP]
StringIndex=1
That didn't work for me either. On Dark Sky, it shows that it's getting the calls, but nothing is displaying on my desktop. Now it's just the degree sign (thanks for the help with that jsmorley!) Like I said before, there are multiple values named temperature that might be causing some problems. They are under different parts of the JSON, does anyone know how I can isolate one?
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: JSON Parsing

Post by FreeRaider »

Starting from your first post:

Code: Select all

RegExp=(?siU).*"currently": \{.*"temperature":(.*),.*
Anyway, I agree with jsmorley, because that A with ^ is a unicode problem.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: JSON Parsing

Post by balala »

takochako, are you using the following URL: URL=https://darksky.net/forecast/#Latitude#,#Longitude#/si24/en (where obviously the Latitude and Longitude variables must be defined properly in the [Variables] section)?
User avatar
fonpaolo
Moderator
Posts: 1387
Joined: April 11th, 2013, 8:08 pm
Location: Italy

Re: JSON Parsing

Post by fonpaolo »

Interesting, Dark Sky is very interesting, only problem it requires a personal key, but:

- the "first" 1000 calls in a day, are free.
- you can personalize the data, include or exclude some.
- you have weather alerts.
- it's translated in many languages.

... and yes, jsmorley, it's a json encoded UTF-8. :uhuh: