It is currently February 20th, 2020, 4:42 pm

JSON Parser

Share and get help with Plugins and Addons
rcurrier
Posts: 6
Joined: May 27th, 2016, 6:34 am

JSON Parser

Post by rcurrier »

Since many (most?) web sites are moving from XML data format to JSON I'm wondering if anyone has tried to write a plugin for JSON parsing? Something like WebJSONParser that takes a URL and returns a table with all of the JSON values (or maybe just the requested ones) that a skin could pull from? I've searched through the forums and via Google but all I can find is a suggestion to use WebParser and a LUA JSON parser. That might work, but it is cumbersome and LUA isn't really the right thing to write a parser in performance wise. I don't have any experience writing a plugin, but do have 15+ years of C/C++ experience and there are many C/C++ parser libraries out there to do the actual parsing. I'm assuming I could use the WebParser code for the network stuff, but even that isn't that hard (the curl library will do that and is easy to call).

I'm not afraid of giving it a try, but if someone already wrote one that works or has a start of one I'd rather write skins. Any suggestions on inputs/outputs or best way to call it would also be appreciated.

= Ron
rcurrier
Posts: 6
Joined: May 27th, 2016, 6:34 am

Re: JSON Parser

Post by rcurrier »

So 22 views and not a single response :confused: . Does that mean no one knows the answer or no one cares about a JSON parser other than myself?
User avatar
jsmorley
Developer
Posts: 20269
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: JSON Parser

Post by jsmorley »

The answer to your original question is probably "no, nobody has written a JSON parser for Rainmeter", at least not that I am aware of.
User avatar
jsmorley
Developer
Posts: 20269
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: JSON Parser

Post by jsmorley »

As to the suggestion, I actually don't care all that much about JSON myself ;-) but have no issue with the concept of someone writing a plugin for Rainmeter that could help with parsing it. I would never in a million years re-invent the wheel and create all the connectivity and downloading stuff that WebParser has, just use a WebParser measure that gets an entire JSON output as input to the JSON parser.

Something like:

Code: Select all

[GetJSON]
Measure=Plugin
Plugin=WebParser
URL=http://somesite.com
RegExp=(?siU)^(.*)$

[GetEmployee2ndLastName]
Measure=Plugin
Plugin=JSON
Source=[GetJSON]
ElementTrail=employees:lastname
ElementCount=2
Or some such.

Code: Select all

{"employees":[
    {"firstName":"John", "lastName":"Doe"},
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}
]}
Returns Smith.
User avatar
fred_gaou
Posts: 60
Joined: July 30th, 2014, 1:00 am

Re: JSON Parser

Post by fred_gaou »

I would love to see a JSON plugin available. Most of web api return JSON table now.
  • Rainmeter 4.2.0 beta r3104 64-bit (Jun 23 2018) - French (1036)
  • Windows 10 Pro 1607 64-bit (build 14393) - French (1036)
  • Path: D:\Programmes\Customisation\Rainmeter\
  • SkinPath: D:\Programmes\Customisation\Rainmeter\Skins\
  • SettingsPath: D:\Programmes\Customisation\Rainmeter\
  • IniFile: D:\Programmes\Customisation\Rainmeter\Rainmeter.ini
rcurrier
Posts: 6
Joined: May 27th, 2016, 6:34 am

Re: JSON Parser

Post by rcurrier »

Thanks jsmorley, this was the sort of input I was hoping for. You are correct as to re-inventing the wheel. While I have in the past written all of that code to get a web page my plan was to either lift the code from WebParser itself or use the open-source CURL library. But using a WebParser measure hadn't occurred to me. It would allow me to concentrate on the JSON parser code. You'll probably care about JSON at some point as everyone is slowly dropping XML in favor of JSON. Thanks for the suggestions.

= Ron