It is currently May 31st, 2020, 12:26 am

Json Parser Plugin

Share and get help with Plugins and Addons
User avatar
raiguard
Posts: 660
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: Json Parser Plugin

Post by raiguard »

So I've already started using this plugin to update my Weather Meter to use Dark Sky, and it is FANTASTIC. It makes it trivial to get Dark Sky's data.

I do have a feature request: could you add an inline function to the plugin for us to get data with? Example:

Code: Select all

[MyMeasure]
Measure=Calc
Formula=[MeasureJson:Query("currently.temperature")] - 1
DynamicVariables=1
Right now if you want to do any edits or arithmetic on retrieved values, you have to create a measure to retrieve the value, then you have to create another measure to do the arithmetic. Being able to use the plugin inline would eliminate that extra measure.

(edit: removed string example because it was redundant)

Thanks in advance! :D

Edit: some more feature requests, if you don't mind :)
- option to disable the log warnings when a token isn't found
- ability to get the number of items in an array
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
incertoe
Posts: 2
Joined: January 17th, 2020, 5:37 am

Re: Json Parser Plugin

Post by incertoe »

Are JsonPath filters working?

I've been trying to run a jsonPath query using the [?@] syntax. In my case I'm querying a Json object's children like the line below

The following snippet works in a jsonPath tester:
initialClasses[?(@.category=='Water')].category
User avatar
e2e8
Posts: 8
Joined: January 5th, 2020, 8:18 am

Re: Json Parser Plugin

Post by e2e8 »

raiguard wrote:
January 17th, 2020, 2:16 am
inline function
I will look into section variables.

Code: Select all

Formula=[MeasureJson:Query("currently.temperature")] - 1
Is the idea for this that it would reuse the source from the initial measure?

Perhaps something like this may also work.

Code: Select all

Formula=[MeasureJson:Query([&Source],"currently.temperature")] - 1
raiguard wrote:
January 17th, 2020, 2:16 am
- option to disable the log warnings when a token isn't found
Something like this okay?

Code: Select all

NoMatch=ignore
raiguard wrote:
January 17th, 2020, 2:16 am
- ability to get the number of items in an array
Looks like JsonPath does specify a length function but it is not implemented in NewtonSoft Json. So this will have to be custom. hmm
I was thinking about this originally. Currently objects and arrays are just turned back into strings but seems like not the most useful thing so there might need to a way to specify a function to execute on them.

incertoe wrote:
January 17th, 2020, 5:41 am
Are JsonPath filters working?
Should be. Post a full example of your source and query.
User avatar
incertoe
Posts: 2
Joined: January 17th, 2020, 5:37 am

Re: Json Parser Plugin

Post by incertoe »

I can use JSONPATH queries as follows to get results, but I'm hard pressed to get something akin to the following to work in the plugin. Same data and same query. Likely me missing something here.
JSON SAMPLE

Code: Select all


	{  "initialClasses": [
	{
		  "clientId": null,
		  "name": "Zumba",
		  "type": "Class Schedule",
		  "category": "Cardio",
		  "timeOfDay": "Morning"
		},
		{
		  "clientId": null,
		  "name": "Lap Swim",
		  "type": "Class Schedule",
		  "category": "Water",
		  "timeOfDay": "Midday"
		}
	]}
Then the query against it is as follows

Code: Select all


   initialClasses[?(@.category=='Water')].category
   
User avatar
raiguard
Posts: 660
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: Json Parser Plugin

Post by raiguard »

e2e8 wrote:
January 17th, 2020, 8:02 am
Is the idea for this that it would reuse the source from the initial measure?

Perhaps something like this may also work.

Code: Select all

Formula=[MeasureJson:Query([&Source],"currently.temperature")] - 1
Either way is fine. Defining both the source and the query would probably be better in the long run.
e2e8 wrote:
January 17th, 2020, 8:02 am
Something like this okay?

Code: Select all

NoMatch=ignore
That would be okay, though I would do it like Logging=0. That way you could add other logging modes (2,3,4,...) in the future if you wished.
e2e8 wrote:
January 17th, 2020, 8:02 am
Looks like JsonPath does specify a length function but it is not implemented in NewtonSoft Json. So this will have to be custom. hmm
I was thinking about this originally. Currently objects and arrays are just turned back into strings but seems like not the most useful thing so there might need to a way to specify a function to execute on them.
Being able to iterate over a table would be awesome. Maybe an Iterate=1 line could be added, so whenever the measure updates, it will move to the next entry in the array. If you combine that with the ability to get the array length, and a loop measure, then you could perform an action on each element in the array.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
e2e8
Posts: 8
Joined: January 5th, 2020, 8:18 am

Re: Json Parser Plugin

Post by e2e8 »

incertoe wrote:
January 17th, 2020, 3:57 pm
Your sample works fine for me. I just pasted the json (without the newlines) and the query into the skin and it returned 'Water' as expected.
Try enabling debug logging in Rainmeter and take a look at the log file.
User avatar
poisonborz
Posts: 10
Joined: November 25th, 2009, 6:52 pm

Re: Json Parser Plugin

Post by poisonborz »

Just wanted to really thank you for this plugin, this is a godsend for the whole community here - working with json-s, the most popular api response format, was a pretty bad experience with rainmeter until now. This should be included in the default plugins.
nek
Posts: 19
Joined: November 3rd, 2019, 12:00 am

Re: Json Parser Plugin

Post by nek »

Thank you for the awesome JsonParser Plugin and sharing.
wm04.png
I have created a skin icon for the weather.
https://forum.rainmeter.net/viewtopic.php?f=27&t=34524
You do not have the required permissions to view the files attached to this post.
stefansh
Posts: 3
Joined: January 22nd, 2020, 8:19 pm

Re: Json Parser Plugin

Post by stefansh »

FYI, I wrote a DarkSky skin, which you can check out for comparison: https://forum.rainmeter.net/viewtopic.php?f=119&t=34504
User avatar
JelleDekkers
Posts: 53
Joined: September 27th, 2017, 6:32 pm

Re: Json Parser Plugin

Post by JelleDekkers »

Hi, is it possible to parse a value from an item with a space in its name? I'm having trouble parsing it as it just crashes Rainmeter right now.

The value I'm trying to parse is

Code: Select all

"Low Temperature":"Lage temperatuur"
but this just crashes Rainmeter:

Code: Select all

[mTranslationLowTemp]
Group=TWC
Measure=Plugin
Plugin=JsonParser

Source=[mTranslationParent]
Query="Low Temperature"

UpdateDivider=-1
Disabled=1