
It is currently May 29th, 2023, 3:42 am
Json Parser Plugin
-
- Posts: 76
- Joined: January 8th, 2017, 2:31 am
- Location: Charlotte, NC
-
- Posts: 2
- Joined: April 4th, 2023, 3:06 pm
Re: Json Parser Plugin
Hi Sorry to dig up such an old thread, but hoping someone might be able to assist on this error.
I am trying to pull the name field after filtering for a specific server name in a json file. json file data seems to be downloading just fine. plugin seems to load no issues. But I am getting a "Error reading JToken from JsonReader. Path '', line 0, position 0." error on the logs whenever I try to query up for the information I need.
Below is the code I am currently using along with log.
Log
I am trying to pull the name field after filtering for a specific server name in a json file. json file data seems to be downloading just fine. plugin seems to load no issues. But I am getting a "Error reading JToken from JsonReader. Path '', line 0, position 0." error on the logs whenever I try to query up for the information I need.
Below is the code I am currently using along with log.
-
- Rainmeter Sage
- Posts: 5337
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: Json Parser Plugin
There are several problems with your approach:ElMalditoBatman wrote: ↑April 4th, 2023, 3:13 pm Hi Sorry to dig up such an old thread, but hoping someone might be able to assist on this error.
I am trying to pull the name field after filtering for a specific server name in a json file. json file data seems to be downloading just fine. plugin seems to load no issues. But I am getting a "Error reading JToken from JsonReader. Path '', line 0, position 0." error on the logs whenever I try to query up for the information I need.
1) the JSON is huge (24000+ records, 34.5 MB saved, 532000+ lines after formatting), so its retrieval is far from instantaneous - hence the error since the Source option has an empty (e.g. invalid) value before the entire data is eventually received by Rainmeter
2) the value of the RegExp option in your WebParser measure needs to be (?siU)^(.*?)$ so that the ? after the * inverts the ungreedy matching set by the ?U flag and captures as many characters as possible (aka all)
3) the value of the Query option in your JsonParser measure is incorrect - I suggest you study the details about the syntax of such a query by checking out the NewtonSoft link from the first post in this thread, in order to understand the changes to it below
4) dynamic variables need to be enabled in the JsonParser measure, since it references the WebParser measure which changes over the course of the process - alternatively, I guess you could use Source=[&MeasureArkServerList] instead of enabling them
The code (I left some comments there for conveniency):
Code: Select all
[Rainmeter]
Update=10000
AccurateText=1
DynamicWindowSize=1
--- First test sample from https://www.newtonsoft.com/json/help/html/SelectToken.htm with new lines removed ---
; [MeasureTest]
; Measure=String
; String="{ 'Stores': [ 'Lambton Quay', 'Willis Street' ], 'Manufacturers': [ { 'Name': 'Acme Co', 'Products': [ { 'Name': 'Anvil', 'Price': 50 } ] }, { 'Name': 'Contoso', 'Products': [ { 'Name': 'Elbow Grease', 'Price': 99.95 }, { 'Name': 'Headlight Fluid', 'Price': 4 } ] } ]}"
; [MeasureManufacturerName]
; Measure=Plugin
; Plugin=JsonParser.dll
; Source=[MeasureTest]
; Query="Manufacturers[0].Name"
; DynamicVariables=1
--- Actual sample from http://arkdedicated.com/xbox/cache/unofficialserverlist.json ---
; REFERENCES:
; - SourcePage: http://arkdedicated.com/xbox/cache/unofficialserverlist.json
; - Formatting: https://webformatter.com/
; - Query Info: https://www.newtonsoft.com/json/help/html/SelectToken.htm
[MeasureArkServerList]
Measure=WebParser
URL=http://arkdedicated.com/xbox/cache/unofficialserverlist.json
RegExp=(?siU)^(.*?)$
[MeasureNumPlayers]
Measure=Plugin
Plugin=JsonParser.dll
Source=[MeasureArkServerList]
Query="$[?(@.Name == '[US] Back Seat Gaming Official')].MapName"
DynamicVariables=1
--- Meters ---
[MapGenesisLabel]
Meter=String
X=5
Y=3R
W=300
H=15
FontSize=11
FontColor=255,225,181,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Genesis 1:
[MeterGenesisPlayers]
Meter=String
MeasureName=MeasureNumPlayers
X=315
Y=0r
W=300
H=15
FontSize=11
FontColor=252,251,202,255
SolidColor=0,0,0,1
Padding=5,5,5,5
StringAlign=Right
AntiAlias=1
You do not have the required permissions to view the files attached to this post.
-
- Posts: 2
- Joined: April 4th, 2023, 3:06 pm
Re: Json Parser Plugin
Dude you are amazing!. Thank you! And yes, I figured it had something to do with the huge json file. This is my first time working with rainmeter, and I appreciate all the notes. I was having trouble finding others with a similar matter to learn off of.
-
- Rainmeter Sage
- Posts: 5337
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: Json Parser Plugin
You're welcome - glad to help. Thanks for the appreciation, others here are too!ElMalditoBatman wrote: ↑April 4th, 2023, 7:12 pm Dude you are amazing!. Thank you! And yes, I figured it had something to do with the huge json file. This is my first time working with rainmeter, and I appreciate all the notes. I was having trouble finding others with a similar matter to learn off of.
Take your time and enjoy working with Rainmeter, and good luck with the rest of the JSON querying process!

-
- Posts: 21
- Joined: January 24th, 2022, 2:54 pm
- Location: World Wide Web
Re: Json Parser Plugin
Hi, im working on my suite which uses your JsonParser plugin to check for updates. I have one major problem with this plugin, it works how it should but every time the page in my panel loads this error is printed into rainmeter logs.
Error:
My version.json:
My code for update:
Error:
Code: Select all
Error reading JToken from JsonReader. Path '', line 0, position 0. (ashuramaru\panel\panel.ini - [Measure_Version_Parse])
Error reading JToken from JsonReader. Path '', line 0, position 0. (ashuramaru\panel\panel.ini - [Measure_Version_Parse])
Code: Select all
{
"Ashuramaru_Bundle": [
{
"version": "1.1.1"
}
]
}
Code: Select all
[Measure_Version]
Measure=Webparser
Url=https://raw.githubusercontent.com/Kurou-kun/Ashuramaru-Bundle/main/version.json
RegExp=(?siU)^(.*?)$
OnConnectErrorAction=[!Log "Couldn't connect to the destination!"]
OnRegExpErrorAction=[!Log "RegExp Exception!"]
[Measure_Version_Parse]
Measure=Plugin
Plugin=JsonParser
Source=[Measure_Version]
Query="Ashuramaru_Bundle[0].version"
UpdateRate=500
DynamicVariables=1
OnUpdateAction=[!CommandMeasure "Script_Panel" "upgrade('[Measure_Version_Parse]')"] <-- This function just toggles meters basing on the provided value
Brought to you by: https://kinmokusei.dev/
-
- Rainmeter Sage
- Posts: 5337
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: Json Parser Plugin
I don't know what could be the problem, since it doesn't seem like an misformatted query or anything like it (i.e. even commenting out the query altogether doesn't get rid of the error). Might be one of those initial errors at skin parsing / loading time, when everything is empty and you have side effects until the data is retrieved, considering we talk about a WebParser measure as a source. The curious thing is that starting with the plugin measure initially disabled should solve it, but for some reason, it doesn't.
That being said, there are some things that are not exactly optimal in your code, like the UpdateRate in the plugin measure instead of the WebParser one, or having an UpdateAction that, as it currently is, is executed every second, according to the Update value (and not the UpdateRate). Therefore, a better implementation would be along these lines (I replaced the OnUpdateAction with a Rainmeter log message to better see the differences):
Code: Select all
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
---Measures---
[Measure_Version]
Measure=WebParser
Url=https://raw.githubusercontent.com/Kurou-kun/Ashuramaru-Bundle/main/version.json
RegExp=(?s)^(.*)$
UpdateRate=500
OnConnectErrorAction=[!Log "Couldn't connect to the destination!"]
OnRegExpErrorAction=[!Log "RegExp Exception!"]
FinishAction=[!EnableMeasure Measure_Version_Parse][!UpdateMeasure Measure_Version_Parse][!UpdateMeter SomeMeter][!Redraw]
DynamicVariables=1
[Measure_Version_Parse]
Disabled=1
Measure=Plugin
Plugin=JsonParser.dll
Source=[Measure_Version]
Query="Ashuramaru_Bundle[0].version"
UpdateDivider=-1
OnUpdateAction=[!Log "Updated"]
DynamicVariables=1
---Meters---
[SomeMeter]
Meter=String
SolidColor=0,0,0,1
FontColor=100,255,100,255
FontFace=Consolas
FontSize=16
AntiAlias=1
MeasureName=Measure_Version_Parse
Text=Version: %1
UpdateDivider=-1
LeftMouseUpAction=[!EnableMeasure Measure_Version_Parse][!UpdateMeasure Measure_Version_Parse][!UpdateMeter SomeMeter][!Redraw]
DynamicVariables=1
So, the error still occurs, but you shouldn't worry about it. The plugin developer should probably be more knowledgeable on why this happens and whether some fix is needed.
-
- Posts: 21
- Joined: January 24th, 2022, 2:54 pm
- Location: World Wide Web
Re: Json Parser Plugin
Got itYincognito wrote: ↑May 25th, 2023, 4:59 pm I don't know what could be the problem, since it doesn't seem like an misformatted query or anything like it (i.e. even commenting out the query altogether doesn't get rid of the error). Might be one of those initial errors at skin parsing / loading time, when everything is empty and you have side effects until the data is retrieved, considering we talk about a WebParser measure as a source. The curious thing is that starting with the plugin measure initially disabled should solve it, but for some reason, it doesn't.
Brought to you by: https://kinmokusei.dev/