JSON Parser Actor for macOS and Windows (public beta)
-
Dear All,
Because of some posts by @bonemap and @robhblack I whipped together an actor that will parse JSON Strings.
Basically you input any JSON string to the 'json in' input. The 'elements' output will update to show you how many top level elements were found. You will the want to set the 'selectors' input to specify how many selectors you would like to access, and finally enter the the selector names in 'select 1', 'select 2', etc.
For example, this json string
{ "first_name" : "Mark", "last_name" : "Coniglio", "employer" : "TroikaTronix" }
Would be parsed by setting up the JSON Parser as follows:
When the souce data is an array (i.e., enclosed by square brackets [ ] ) then you need to access the items by index, starting at 0.
[ "Mark", "Coniglio", "TroikaTronix" ]
If one of those elements is an "object" -- meaning it is a list enclosed by curly brackets (e.g., { and } ) then you would use a second JSON Parser to pull extract those values
{ "first_name" : "Mark", "last_name" : "Coniglio", "employer" : "TroikaTronix", "jobs" : { "job_1" : "bus boy", "job_2" : "programmer", "job_3" : "record producer" } }
Or, you can access en embedded element by using a string of selectors separated by a colons. For example, the selector jobs:job_1 will give you the element job_1 inside of the jobs.
Obviously we'll need better instructions for this. But since this is more of an advanced feature that will not be so widely used, I thought I'd get it out there now and let you all have a go and offer any feedback.
(Before you ask: no, I haven't made an actor to go the other direction yet. One step at a time. ;-) )
Here's an example file you can play with. It includes the Get URL Text actor in the third scene, replicating the task that @bonemap and @robhblack were talking about.
Finally, here's the .zip file with the actors themselves for both MacOS and Windows.
(This plugin is notarized for Catalina.)
Once we know this is working, we'll get it uploaded to the plugins page. In the meantime, post any issues here.
Have Fun,
Mark -
Edited on March 24, 2020: fixed a bug in 0.9.0 where you could not access arrays by index. Improved the instructions.
-
NOTE: the previou upload of the JSON Parser v0.9.1 did not have the Windows plugin. I have re-uploaded a corrected version on April 8, 2020 at 11:30 CEST. If you're missing the windows plugin, just download it again.
Best Wishes,
Mark