Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 21:12 04 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Json$ parsing help

Author Message
Doktorn

Newbie

Joined: 09/07/2019
Location: Sweden
Posts: 18
Posted: 02:35pm 02 Nov 2025
Copy link to clipboard 
Print this post

Hi

I have a Json$ file with multiple instances of a label ”SEK_per_kWh”.
On another system I can use  print Json$(x$,”SEK_per_kWh[6]”) for
instance nbr 6. I have tried with Print Json$(inp%(),”SEK_per_kWh”)
witch correctly give me the first post but Print Json$(inp%(),”SEK_per_kWh[6]”)
gives nothing.

Can’t get it to work in MM RP2040 V6.00.01.RC6.

My question, how can I parse a Json file with multiple  instances of
the same label.

/Lasse
N/A
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3455
Posted: 02:43pm 02 Nov 2025
Copy link to clipboard 
Print this post

Post your entire json string.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Doktorn

Newbie

Joined: 09/07/2019
Location: Sweden
Posts: 18
Posted: 02:50pm 02 Nov 2025
Copy link to clipboard 
Print this post

Hi

The file is large, 13620 bytes.

It's  this times 96

{"SEK_per_kWh":0.27497,"EUR_per_kWh":0.02498,"EXR":11.007546,"time_start":"2025-11-02T00:00:00+01:00","time_end":"2025-11-02T00:15:00+01:00"}

/Lasse
N/A
 
Pluto
Guru

Joined: 09/06/2017
Location: Finland
Posts: 394
Posted: 03:43pm 02 Nov 2025
Copy link to clipboard 
Print this post

Hi Lasse,
It seems that we are working with very similar topics! You are parsing swedish and myself finnish electricity prices.

Starting from the long Json$ string (stoted in a longsting buffer) I first search for the first "{" and remove everything up to that point. Then search for the keywords in the Json$. Save data in arrays.
Then again remove the "used" part of the Json$ (LONGSTRING TRIM buff%(),1) and the starting over again.

Here is short part of my code:
WEB open TCP CLIENT url$,80
 WEB TCP CLIENT REQUEST Query$,buff%(),15000
 WEB close TCP CLIENT
 print "TCP time:",timer,"ms"
 'a%: position of first "{" in buff%().
 print "LLEN(buff%() Part 1:";LLEN(buff%())
 a%=LinStr(buff%(),"{")-1: if deb then print "a%=";a%
 
 If a% <> -1 Then
   'LongString trim buff%(),a% 'tar bort a% tecken fr?n b?rjan av buff%()
   if deb then Print "buff%()=",
   if deb then LongString print buff%()
   
   for i=1 to 48
     
     a%=LinStr(buff%(),"{")-1 'find position of first {
     LongString trim buff%(),a% 'remove all before {
     
     PriceQuart(i)=CINT(val(Json$(buff%(),"hinta"))*1.255*100)/100 'incl 25.5% VAT
     ClockQuart$(i)=right$(Json$(buff%(),"aikaleima_suomi"),5)
     
     a%=a%+1
     LongString trim buff%(),1 'remove first char left in buff().(should be "{")
     
   next i
 

For some unknown reason I was not able to get all 96 datapoints reliably received at once; hence i=1 to 48. (And later a similar sequence for i=49 to 96)

Short dictionary:
hinta: price
aikaleima_suomi: timelabel_finland

My code is based on what others have published on thebackshed. You will probably find better explanations by others in this forum.

Lycka till!

Pluto
 
Doktorn

Newbie

Joined: 09/07/2019
Location: Sweden
Posts: 18
Posted: 08:32pm 02 Nov 2025
Copy link to clipboard 
Print this post

lizby

This is the entire json string.

[{"SEK_per_kWh":0.27497,"EUR_per_kWh":0.02498,"EXR":11.007546,"time_start":"2025-11-02T00:00:00+01:00","time_end":"2025-11-02T00:15:00+01:00"},{"SEK_per_kWh":0.22081,"EUR_per_kWh":0.02006,"EXR":11.007546,"time_start":"2025-11-02T00:15:00+01:00","time_end":"2025-11-02T00:30:00+01:00"},{"SEK_per_kWh":0.23897,"EUR_per_kWh":0.02171,"EXR":11.007546,"time_start":"2025-11-02T00:30:00+01:00","time_end":"2025-11-02T00:45:00+01:00"},{"SEK_per_kWh":0.21388,"EUR_per_kWh":0.01943,"EXR":11.007546,"time_start":"2025-11-02T00:45:00+01:00","time_end":"2025-11-02T01:00:00+01:00"},{"SEK_per_kWh":0.2797,"EUR_per_kWh":0.02541,"EXR":11.007546,"time_start":"2025-11-02T01:00:00+01:00","time_end":"2025-11-02T01:15:00+01:00"},{"SEK_per_kWh":0.25538,"EUR_per_kWh":0.0232,"EXR":11.007546,"time_start":"2025-11-02T01:15:00+01:00","time_end":"2025-11-02T01:30:00+01:00"},{"SEK_per_kWh":0.22048,"EUR_per_kWh":0.02003,"EXR":11.007546,"time_start":"2025-11-02T01:30:00+01:00","time_end":"2025-11-02T01:45:00+01:00"},{"SEK_per_kWh":0.20441,"EUR_per_kWh":0.01857,"EXR":11.007546,"time_start":"2025-11-02T01:45:00+01:00","time_end":"2025-11-02T02:00:00+01:00"},{"SEK_per_kWh":0.23237,"EUR_per_kWh":0.02111,"EXR":11.007546,"time_start":"2025-11-02T02:00:00+01:00","time_end":"2025-11-02T02:15:00+01:00"},{"SEK_per_kWh":0.24151,"EUR_per_kWh":0.02194,"EXR":11.007546,"time_start":"2025-11-02T02:15:00+01:00","time_end":"2025-11-02T02:30:00+01:00"},{"SEK_per_kWh":0.24954,"EUR_per_kWh":0.02267,"EXR":11.007546,"time_start":"2025-11-02T02:30:00+01:00","time_end":"2025-11-02T02:45:00+01:00"},{"SEK_per_kWh":0.23391,"EUR_per_kWh":0.02125,"EXR":11.007546,"time_start":"2025-11-02T02:45:00+01:00","time_end":"2025-11-02T03:00:00+01:00"},{"SEK_per_kWh":0.30931,"EUR_per_kWh":0.0281,"EXR":11.007546,"time_start":"2025-11-02T03:00:00+01:00","time_end":"2025-11-02T03:15:00+01:00"},{"SEK_per_kWh":0.31052,"EUR_per_kWh":0.02821,"EXR":11.007546,"time_start":"2025-11-02T03:15:00+01:00","time_end":"2025-11-02T03:30:00+01:00"},{"SEK_per_kWh":0.30854,"EUR_per_kWh":0.02803,"EXR":11.007546,"time_start":"2025-11-02T03:30:00+01:00","time_end":"2025-11-02T03:45:00+01:00"},{"SEK_per_kWh":0.27915,"EUR_per_kWh":0.02536,"EXR":11.007546,"time_start":"2025-11-02T03:45:00+01:00","time_end":"2025-11-02T04:00:00+01:00"},{"SEK_per_kWh":0.31041,"EUR_per_kWh":0.0282,"EXR":11.007546,"time_start":"2025-11-02T04:00:00+01:00","time_end":"2025-11-02T04:15:00+01:00"},{"SEK_per_kWh":0.30931,"EUR_per_kWh":0.0281,"EXR":11.007546,"time_start":"2025-11-02T04:15:00+01:00","time_end":"2025-11-02T04:30:00+01:00"},{"SEK_per_kWh":0.30997,"EUR_per_kWh":0.02816,"EXR":11.007546,"time_start":"2025-11-02T04:30:00+01:00","time_end":"2025-11-02T04:45:00+01:00"},{"SEK_per_kWh":0.30062,"EUR_per_kWh":0.02731,"EXR":11.007546,"time_start":"2025-11-02T04:45:00+01:00","time_end":"2025-11-02T05:00:00+01:00"},{"SEK_per_kWh":0.31383,"EUR_per_kWh":0.02851,"EXR":11.007546,"time_start":"2025-11-02T05:00:00+01:00","time_end":"2025-11-02T05:15:00+01:00"},{"SEK_per_kWh":0.31691,"EUR_per_kWh":0.02879,"EXR":11.007546,"time_start":"2025-11-02T05:15:00+01:00","time_end":"2025-11-02T05:30:00+01:00"},{"SEK_per_kWh":0.31955,"EUR_per_kWh":0.02903,"EXR":11.007546,"time_start":"2025-11-02T05:30:00+01:00","time_end":"2025-11-02T05:45:00+01:00"},{"SEK_per_kWh":0.33166,"EUR_per_kWh":0.03013,"EXR":11.007546,"time_start":"2025-11-02T05:45:00+01:00","time_end":"2025-11-02T06:00:00+01:00"},{"SEK_per_kWh":0.33342,"EUR_per_kWh":0.03029,"EXR":11.007546,"time_start":"2025-11-02T06:00:00+01:00","time_end":"2025-11-02T06:15:00+01:00"},{"SEK_per_kWh":0.33716,"EUR_per_kWh":0.03063,"EXR":11.007546,"time_start":"2025-11-02T06:15:00+01:00","time_end":"2025-11-02T06:30:00+01:00"},{"SEK_per_kWh":0.35158,"EUR_per_kWh":0.03194,"EXR":11.007546,"time_start":"2025-11-02T06:30:00+01:00","time_end":"2025-11-02T06:45:00+01:00"},{"SEK_per_kWh":0.35874,"EUR_per_kWh":0.03259,"EXR":11.007546,"time_start":"2025-11-02T06:45:00+01:00","time_end":"2025-11-02T07:00:00+01:00"},{"SEK_per_kWh":0.36182,"EUR_per_kWh":0.03287,"EXR":11.007546,"time_start":"2025-11-02T07:00:00+01:00","time_end":"2025-11-02T07:15:00+01:00"},{"SEK_per_kWh":0.37194,"EUR_per_kWh":0.03379,"EXR":11.007546,"time_start":"2025-11-02T07:15:00+01:00","time_end":"2025-11-02T07:30:00+01:00"},{"SEK_per_kWh":0.37811,"EUR_per_kWh":0.03435,"EXR":11.007546,"time_start":"2025-11-02T07:30:00+01:00","time_end":"2025-11-02T07:45:00+01:00"},{"SEK_per_kWh":0.38372,"EUR_per_kWh":0.03486,"EXR":11.007546,"time_start":"2025-11-02T07:45:00+01:00","time_end":"2025-11-02T08:00:00+01:00"},{"SEK_per_kWh":0.38548,"EUR_per_kWh":0.03502,"EXR":11.007546,"time_start":"2025-11-02T08:00:00+01:00","time_end":"2025-11-02T08:15:00+01:00"},{"SEK_per_kWh":0.38791,"EUR_per_kWh":0.03524,"EXR":11.007546,"time_start":"2025-11-02T08:15:00+01:00","time_end":"2025-11-02T08:30:00+01:00"},{"SEK_per_kWh":0.39121,"EUR_per_kWh":0.03554,"EXR":11.007546,"time_start":"2025-11-02T08:30:00+01:00","time_end":"2025-11-02T08:45:00+01:00"},{"SEK_per_kWh":0.39418,"EUR_per_kWh":0.03581,"EXR":11.007546,"time_start":"2025-11-02T08:45:00+01:00","time_end":"2025-11-02T09:00:00+01:00"},{"SEK_per_kWh":0.40409,"EUR_per_kWh":0.03671,"EXR":11.007546,"time_start":"2025-11-02T09:00:00+01:00","time_end":"2025-11-02T09:15:00+01:00"},{"SEK_per_kWh":0.40574,"EUR_per_kWh":0.03686,"EXR":11.007546,"time_start":"2025-11-02T09:15:00+01:00","time_end":"2025-11-02T09:30:00+01:00"},{"SEK_per_kWh":0.40244,"EUR_per_kWh":0.03656,"EXR":11.007546,"time_start":"2025-11-02T09:30:00+01:00","time_end":"2025-11-02T09:45:00+01:00"},{"SEK_per_kWh":0.40134,"EUR_per_kWh":0.03646,"EXR":11.007546,"time_start":"2025-11-02T09:45:00+01:00","time_end":"2025-11-02T10:00:00+01:00"},{"SEK_per_kWh":0.4141,"EUR_per_kWh":0.03762,"EXR":11.007546,"time_start":"2025-11-02T10:00:00+01:00","time_end":"2025-11-02T10:15:00+01:00"},{"SEK_per_kWh":0.41091,"EUR_per_kWh":0.03733,"EXR":11.007546,"time_start":"2025-11-02T10:15:00+01:00","time_end":"2025-11-02T10:30:00+01:00"},{"SEK_per_kWh":0.40519,"EUR_per_kWh":0.03681,"EXR":11.007546,"time_start":"2025-11-02T10:30:00+01:00","time_end":"2025-11-02T10:45:00+01:00"},{"SEK_per_kWh":0.40067,"EUR_per_kWh":0.0364,"EXR":11.007546,"time_start":"2025-11-02T10:45:00+01:00","time_end":"2025-11-02T11:00:00+01:00"},{"SEK_per_kWh":0.41102,"EUR_per_kWh":0.03734,"EXR":11.007546,"time_start":"2025-11-02T11:00:00+01:00","time_end":"2025-11-02T11:15:00+01:00"},{"SEK_per_kWh":0.41421,"EUR_per_kWh":0.03763,"EXR":11.007546,"time_start":"2025-11-02T11:15:00+01:00","time_end":"2025-11-02T11:30:00+01:00"},{"SEK_per_kWh":0.41223,"EUR_per_kWh":0.03745,"EXR":11.007546,"time_start":"2025-11-02T11:30:00+01:00","time_end":"2025-11-02T11:45:00+01:00"},{"SEK_per_kWh":0.41256,"EUR_per_kWh":0.03748,"EXR":11.007546,"time_start":"2025-11-02T11:45:00+01:00","time_end":"2025-11-02T12:00:00+01:00"},{"SEK_per_kWh":0.41598,"EUR_per_kWh":0.03779,"EXR":11.007546,"time_start":"2025-11-02T12:00:00+01:00","time_end":"2025-11-02T12:15:00+01:00"},{"SEK_per_kWh":0.50536,"EUR_per_kWh":0.04591,"EXR":11.007546,"time_start":"2025-11-02T12:15:00+01:00","time_end":"2025-11-02T12:30:00+01:00"},{"SEK_per_kWh":0.64603,"EUR_per_kWh":0.05869,"EXR":11.007546,"time_start":"2025-11-02T12:30:00+01:00","time_end":"2025-11-02T12:45:00+01:00"},{"SEK_per_kWh":0.70481,"EUR_per_kWh":0.06403,"EXR":11.007546,"time_start":"2025-11-02T12:45:00+01:00","time_end":"2025-11-02T13:00:00+01:00"},{"SEK_per_kWh":0.65957,"EUR_per_kWh":0.05992,"EXR":11.007546,"time_start":"2025-11-02T13:00:00+01:00","time_end":"2025-11-02T13:15:00+01:00"},{"SEK_per_kWh":0.66959,"EUR_per_kWh":0.06083,"EXR":11.007546,"time_start":"2025-11-02T13:15:00+01:00","time_end":"2025-11-02T13:30:00+01:00"},{"SEK_per_kWh":0.72441,"EUR_per_kWh":0.06581,"EXR":11.007546,"time_start":"2025-11-02T13:30:00+01:00","time_end":"2025-11-02T13:45:00+01:00"},{"SEK_per_kWh":0.72551,"EUR_per_kWh":0.06591,"EXR":11.007546,"time_start":"2025-11-02T13:45:00+01:00","time_end":"2025-11-02T14:00:00+01:00"},{"SEK_per_kWh":0.74345,"EUR_per_kWh":0.06754,"EXR":11.007546,"time_start":"2025-11-02T14:00:00+01:00","time_end":"2025-11-02T14:15:00+01:00"},{"SEK_per_kWh":0.7516,"EUR_per_kWh":0.06828,"EXR":11.007546,"time_start":"2025-11-02T14:15:00+01:00","time_end":"2025-11-02T14:30:00+01:00"},{"SEK_per_kWh":0.75479,"EUR_per_kWh":0.06857,"EXR":11.007546,"time_start":"2025-11-02T14:30:00+01:00","time_end":"2025-11-02T14:45:00+01:00"},{"SEK_per_kWh":0.75336,"EUR_per_kWh":0.06844,"EXR":11.007546,"time_start":"2025-11-02T14:45:00+01:00","time_end":"2025-11-02T15:00:00+01:00"},{"SEK_per_kWh":0.76877,"EUR_per_kWh":0.06984,"EXR":11.007546,"time_start":"2025-11-02T15:00:00+01:00","time_end":"2025-11-02T15:15:00+01:00"},{"SEK_per_kWh":0.79023,"EUR_per_kWh":0.07179,"EXR":11.007546,"time_start":"2025-11-02T15:15:00+01:00","time_end":"2025-11-02T15:30:00+01:00"},{"SEK_per_kWh":0.79067,"EUR_per_kWh":0.07183,"EXR":11.007546,"time_start":"2025-11-02T15:30:00+01:00","time_end":"2025-11-02T15:45:00+01:00"},{"SEK_per_kWh":0.84868,"EUR_per_kWh":0.0771,"EXR":11.007546,"time_start":"2025-11-02T15:45:00+01:00","time_end":"2025-11-02T16:00:00+01:00"},{"SEK_per_kWh":0.87004,"EUR_per_kWh":0.07904,"EXR":11.007546,"time_start":"2025-11-02T16:00:00+01:00","time_end":"2025-11-02T16:15:00+01:00"},{"SEK_per_kWh":0.88236,"EUR_per_kWh":0.08016,"EXR":11.007546,"time_start":"2025-11-02T16:15:00+01:00","time_end":"2025-11-02T16:30:00+01:00"},{"SEK_per_kWh":0.89656,"EUR_per_kWh":0.08145,"EXR":11.007546,"time_start":"2025-11-02T16:30:00+01:00","time_end":"2025-11-02T16:45:00+01:00"},{"SEK_per_kWh":0.90251,"EUR_per_kWh":0.08199,"EXR":11.007546,"time_start":"2025-11-02T16:45:00+01:00","time_end":"2025-11-02T17:00:00+01:00"},{"SEK_per_kWh":0.91429,"EUR_per_kWh":0.08306,"EXR":11.007546,"time_start":"2025-11-02T17:00:00+01:00","time_end":"2025-11-02T17:15:00+01:00"},{"SEK_per_kWh":0.94059,"EUR_per_kWh":0.08545,"EXR":11.007546,"time_start":"2025-11-02T17:15:00+01:00","time_end":"2025-11-02T17:30:00+01:00"},{"SEK_per_kWh":0.94467,"EUR_per_kWh":0.08582,"EXR":11.007546,"time_start":"2025-11-02T17:30:00+01:00","time_end":"2025-11-02T17:45:00+01:00"},{"SEK_per_kWh":0.98231,"EUR_per_kWh":0.08924,"EXR":11.007546,"time_start":"2025-11-02T17:45:00+01:00","time_end":"2025-11-02T18:00:00+01:00"},{"SEK_per_kWh":0.92496,"EUR_per_kWh":0.08403,"EXR":11.007546,"time_start":"2025-11-02T18:00:00+01:00","time_end":"2025-11-02T18:15:00+01:00"},{"SEK_per_kWh":0.95083,"EUR_per_kWh":0.08638,"EXR":11.007546,"time_start":"2025-11-02T18:15:00+01:00","time_end":"2025-11-02T18:30:00+01:00"},{"SEK_per_kWh":0.94797,"EUR_per_kWh":0.08612,"EXR":11.007546,"time_start":"2025-11-02T18:30:00+01:00","time_end":"2025-11-02T18:45:00+01:00"},{"SEK_per_kWh":0.8991,"EUR_per_kWh":0.08168,"EXR":11.007546,"time_start":"2025-11-02T18:45:00+01:00","time_end":"2025-11-02T19:00:00+01:00"},{"SEK_per_kWh":0.89921,"EUR_per_kWh":0.08169,"EXR":11.007546,"time_start":"2025-11-02T19:00:00+01:00","time_end":"2025-11-02T19:15:00+01:00"},{"SEK_per_kWh":0.88424,"EUR_per_kWh":0.08033,"EXR":11.007546,"time_start":"2025-11-02T19:15:00+01:00","time_end":"2025-11-02T19:30:00+01:00"},{"SEK_per_kWh":0.87928,"EUR_per_kWh":0.07988,"EXR":11.007546,"time_start":"2025-11-02T19:30:00+01:00","time_end":"2025-11-02T19:45:00+01:00"},{"SEK_per_kWh":0.85925,"EUR_per_kWh":0.07806,"EXR":11.007546,"time_start":"2025-11-02T19:45:00+01:00","time_end":"2025-11-02T20:00:00+01:00"},{"SEK_per_kWh":0.87631,"EUR_per_kWh":0.07961,"EXR":11.007546,"time_start":"2025-11-02T20:00:00+01:00","time_end":"2025-11-02T20:15:00+01:00"},{"SEK_per_kWh":0.86244,"EUR_per_kWh":0.07835,"EXR":11.007546,"time_start":"2025-11-02T20:15:00+01:00","time_end":"2025-11-02T20:30:00+01:00"},{"SEK_per_kWh":0.85804,"EUR_per_kWh":0.07795,"EXR":11.007546,"time_start":"2025-11-02T20:30:00+01:00","time_end":"2025-11-02T20:45:00+01:00"},{"SEK_per_kWh":0.85463,"EUR_per_kWh":0.07764,"EXR":11.007546,"time_start":"2025-11-02T20:45:00+01:00","time_end":"2025-11-02T21:00:00+01:00"},{"SEK_per_kWh":0.75864,"EUR_per_kWh":0.06892,"EXR":11.007546,"time_start":"2025-11-02T21:00:00+01:00","time_end":"2025-11-02T21:15:00+01:00"},{"SEK_per_kWh":0.65693,"EUR_per_kWh":0.05968,"EXR":11.007546,"time_start":"2025-11-02T21:15:00+01:00","time_end":"2025-11-02T21:30:00+01:00"},{"SEK_per_kWh":0.60707,"EUR_per_kWh":0.05515,"EXR":11.007546,"time_start":"2025-11-02T21:30:00+01:00","time_end":"2025-11-02T21:45:00+01:00"},{"SEK_per_kWh":0.55302,"EUR_per_kWh":0.05024,"EXR":11.007546,"time_start":"2025-11-02T21:45:00+01:00","time_end":"2025-11-02T22:00:00+01:00"},{"SEK_per_kWh":0.63161,"EUR_per_kWh":0.05738,"EXR":11.007546,"time_start":"2025-11-02T22:00:00+01:00","time_end":"2025-11-02T22:15:00+01:00"},{"SEK_per_kWh":0.62061,"EUR_per_kWh":0.05638,"EXR":11.007546,"time_start":"2025-11-02T22:15:00+01:00","time_end":"2025-11-02T22:30:00+01:00"},{"SEK_per_kWh":0.6053,"EUR_per_kWh":0.05499,"EXR":11.007546,"time_start":"2025-11-02T22:30:00+01:00","time_end":"2025-11-02T22:45:00+01:00"},{"SEK_per_kWh":0.55533,"EUR_per_kWh":0.05045,"EXR":11.007546,"time_start":"2025-11-02T22:45:00+01:00","time_end":"2025-11-02T23:00:00+01:00"},{"SEK_per_kWh":0.42423,"EUR_per_kWh":0.03854,"EXR":11.007546,"time_start":"2025-11-02T23:00:00+01:00","time_end":"2025-11-02T23:15:00+01:00"},{"SEK_per_kWh":0.42126,"EUR_per_kWh":0.03827,"EXR":11.007546,"time_start":"2025-11-02T23:15:00+01:00","time_end":"2025-11-02T23:30:00+01:00"},{"SEK_per_kWh":0.41851,"EUR_per_kWh":0.03802,"EXR":11.007546,"time_start":"2025-11-02T23:30:00+01:00","time_end":"2025-11-02T23:45:00+01:00"},{"SEK_per_kWh":0.41653,"EUR_per_kWh":0.03784,"EXR":11.007546,"time_start":"2025-11-02T23:45:00+01:00","time_end":"2025-11-03T00:00:00+01:00"}]


/Lasse
N/A
 
Doktorn

Newbie

Joined: 09/07/2019
Location: Sweden
Posts: 18
Posted: 09:08pm 02 Nov 2025
Copy link to clipboard 
Print this post

Hi Pluto

Thanks for the tip about parsing my Json$ file. I have used a similar technique when I
decoded XML price documents from the entsoe price database a couple of years ago.
I have an application on an ESP32 with Annex RDS that works well where you can use Json$
in the following way  pris$(1)=json$(le$,"SEK_per_kWh[1]”),pris$(2)=json$(le$,"SEK_per_kWh[2]”)
etc. What I was looking for was from the manual's description of the JSON$ parser.

From the manual.
JSON$(a%(), “weather[0].description”)  What does the number within [0] mean?

/Lasse
N/A
 
Pluto
Guru

Joined: 09/06/2017
Location: Finland
Posts: 394
Posted: 08:17am 03 Nov 2025
Copy link to clipboard 
Print this post

  Quote  JSON$(a%(), “weather[0].description”)  What does the number within [0] mean?


The data returned as "weather[0].description" is just a text-string explaining the weather, like "overcast clouds", broken clouds", "heavy snow", "rain" etc.

I have never tried e.g. weather[1].description. I assume that you can have several weather conditions at the same location, e.g. "heavy rain", "strong wind".

Pluto
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3455
Posted: 03:34pm 03 Nov 2025
Copy link to clipboard 
Print this post

I no longer have convenient a webmite with which to test, but from past posts, this is what is typically returned from api.openweathermap.org

  Quote  {"coord":{"lon":-64.7155,"lat":44.0335},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"base":"stations","main":{"temp":278.94,"feels_like":269.44,"temp_min":278.71,"temp_max":279.15,"pressure":1008,"humidity":56},"visibility":10000,"wind":{"speed":10.29,"deg":240,"gust":14.92},"clouds":{"all":46},"dt":1612635812,"sys":{"type":1,"id":549,"country":"CA","sunrise":1612611013,"sunset":1612647345},"timezone":-14400,"id":6057856,"name":"Liverpool","cod":200}


There is no weather[1], only a single instance of the weather values (within "[]"). (But the structure is such that there could be multiple instances.)

The problem that I see with the json string given is that there is no "name" for the multiple "value" instances to be referenced by, and I don't know if there is syntax for which that might work with the MMBasic implementation of json. I made a brief attempt with a picomite and a limited json file using ".[i].SEK_per_kWh"), but got "Error : Dimensions".

I did ask ChatGPT-5 to make a bash script to extract the value. I created a file with just the first 15 values:
  Quote  [{"SEK_per_kWh":0.27497,"EUR_per_kWh":0.02498,"EXR":11.007546,"time_start":"2025-11-02T00:00:00+01:00","time_end":"2025-11-02T00:15:00+01:00"},
{"SEK_per_kWh":0.22081,"EUR_per_kWh":0.02006,"EXR":11.007546,"time_start":"2025-11-02T00:15:00+01:00","time_end":"2025-11-02T00:30:00+01:00"},
{"SEK_per_kWh":0.23897,"EUR_per_kWh":0.02171,"EXR":11.007546,"time_start":"2025-11-02T00:30:00+01:00","time_end":"2025-11-02T00:45:00+01:00"},
{"SEK_per_kWh":0.21388,"EUR_per_kWh":0.01943,"EXR":11.007546,"time_start":"2025-11-02T00:45:00+01:00","time_end":"2025-11-02T01:00:00+01:00"},
{"SEK_per_kWh":0.2797,"EUR_per_kWh":0.02541,"EXR":11.007546,"time_start":"2025-11-02T01:00:00+01:00","time_end":"2025-11-02T01:15:00+01:00"},
{"SEK_per_kWh":0.25538,"EUR_per_kWh":0.0232,"EXR":11.007546,"time_start":"2025-11-02T01:15:00+01:00","time_end":"2025-11-02T01:30:00+01:00"},
{"SEK_per_kWh":0.22048,"EUR_per_kWh":0.02003,"EXR":11.007546,"time_start":"2025-11-02T01:30:00+01:00","time_end":"2025-11-02T01:45:00+01:00"},
{"SEK_per_kWh":0.20441,"EUR_per_kWh":0.01857,"EXR":11.007546,"time_start":"2025-11-02T01:45:00+01:00","time_end":"2025-11-02T02:00:00+01:00"},
{"SEK_per_kWh":0.23237,"EUR_per_kWh":0.02111,"EXR":11.007546,"time_start":"2025-11-02T02:00:00+01:00","time_end":"2025-11-02T02:15:00+01:00"},
{"SEK_per_kWh":0.24151,"EUR_per_kWh":0.02194,"EXR":11.007546,"time_start":"2025-11-02T02:15:00+01:00","time_end":"2025-11-02T02:30:00+01:00"},
{"SEK_per_kWh":0.24954,"EUR_per_kWh":0.02267,"EXR":11.007546,"time_start":"2025-11-02T02:30:00+01:00","time_end":"2025-11-02T02:45:00+01:00"},
{"SEK_per_kWh":0.23391,"EUR_per_kWh":0.02125,"EXR":11.007546,"time_start":"2025-11-02T02:45:00+01:00","time_end":"2025-11-02T03:00:00+01:00"},
{"SEK_per_kWh":0.30931,"EUR_per_kWh":0.0281,"EXR":11.007546,"time_start":"2025-11-02T03:00:00+01:00","time_end":"2025-11-02T03:15:00+01:00"},
{"SEK_per_kWh":0.31052,"EUR_per_kWh":0.02821,"EXR":11.007546,"time_start":"2025-11-02T03:15:00+01:00","time_end":"2025-11-02T03:30:00+01:00"},
{"SEK_per_kWh":0.30854,"EUR_per_kWh":0.02803,"EXR":11.007546,"time_start":"2025-11-02T03:30:00+01:00","time_end":"2025-11-02T03:45:00+01:00
"}]


Here's the Linux command line, and the results (run on a Seagate Dockstar flashed with openWrt):
  Quote  cat Sw_kwh.json | jq -r '.[] | .SEK_per_kWh'
0.27497
0.22081
0.23897
0.21388
0.2797
0.25538
0.22048
0.20441
0.23237
0.24151
0.24954
0.23391
0.30931
0.31052
0.30854


In that command the "." in ".[]" implies the entire json string.

I don't know if there is magic which would make a MMBasic json query work with this particular json string.

~
Edited 2025-11-04 01:45 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10553
Posted: 03:53pm 03 Nov 2025
Copy link to clipboard 
Print this post

The json listed doesn't conform to the norm. There should be an outer name and then you could access as an array
{
 "users": [
   { "name": "Alice", "age": 30 },
   { "name": "Bob", "age": 25 }
 ]
}


users[1].name

Try appending a name at the beginning and a close bracket at the end as in my example and see if the json$ function then works
 
Pluto
Guru

Joined: 09/06/2017
Location: Finland
Posts: 394
Posted: 05:02pm 03 Nov 2025
Copy link to clipboard 
Print this post

Lasse,
your data seems to have the same structure as my data so it should be possible to extract your data with the same procedure as I have used. link to earlier post

[{"aikaleima_suomi":"2025-11-03T00:00","aikaleima_utc":"2025-11-02T22:00","hinta":1.544},{"aikaleima_suomi":"2025-11-03T00:15","aikaleima_utc":"2025-11-02T22:15","hinta":1.508},{"aikaleima_suomi":"2025-11-03T00:30","aikaleima_utc":"2025-11-02T22:30","hinta":1.468},{"aikaleima_suomi":"2025-11-03T00:45","aikaleima_utc":"2025-11-02T22:45","hinta":1.448},{"aikaleima_suomi":"2025-11-03T01:00","aikaleima_utc":"2025-11-02T23:00","hinta":1.307},{"aikaleima_suomi":"2025-11-03T01:15","aikaleima_utc":"2025-11-02T23:15","hinta":0.749},......]


(Full day 96 points, but I had to make two TCP requests á 48 points).

Pluto
 
Doktorn

Newbie

Joined: 09/07/2019
Location: Sweden
Posts: 18
Posted: 09:28pm 03 Nov 2025
Copy link to clipboard 
Print this post

Thanks everyone for the tips and suggestions.

matherp, your suggestion about adding group name to Json$ files is correct. Works as expected. But for now I will use my current design which consists of an ESP32-S3 with Annex RDS which retrieves and beautifies the Json$ file. The ESP32 then sends the result serially to the pico. It works great.

Here on a Pico with 7" SSD1963  ( the SSD1963 is not supported in Annex )

/Lasse



N/A
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025