|
JSON To Structure (Composition by smokris)
Converts a JSON string input into a Structure. Useful in conjunction with the Kineme FileTools "String With URL" patch, to produce an alternative to the built-in XML Importer patch. An example composition is attached, using this patch to parse the results of a Yahoo Search API query. |
Sorry to be the bearer of sad tidings about something that is pretty brilliant - but this is provoking a JavaScript related GF Log message
when the search term has a space - only single word search terms not multiple word strings. a multiple search string will not obtain a search result at all.
The error clears upon presenting a only a single word search term or even character, so not especially serious.
Update - entering terms as say ford/motors providing an escape character by means of the slash character makes this work without a JS error.
Just been tinkering with the Demo comp and obviously enough one can add in additional search boxes [Arguments] to contain discrete terms that build to be the total string. - does work.
I'm on Leopard. Put the JSON_To_Structure.qtz into …/Library/Graphics/Quartz Composer Patches/
When I open JSON_To_Structure_Demo comp it doesn't find the JSON_To_Structure patch. ie Console Error. Manually placing the JSON_To_Structure patch into the comp and joining it to Kineme String With URL and ResultSet patches generates a structure but the same image is being repeated 10 times.
The text gives the different URLs though.
This works on .5 you say ? looks like it isn't reading the JSON output correctly at all apart from the text listing, it just isn't leveraging the underlying .6.2 specific JSON and structure stuff - pity. probably could be 'reverse engineered' to do the same, although virtual macro wise isn't that also .6.x specific? difficult to tell from your mini picture :-) so I've attached my results for your comparison , same misspelt beafheart •~ I do get a range of different text and associated image results, but then I'm running .6.x, so no surprise really. do you also get a js error when presenting a spaced search term, like manchester united whereas manchester/united obtains no error and gets results [by the looks of things , just the textual search results]?
I'm in the most recent 10.6 seed right now, and it's working fine. I had to open the "JSON_To_Structure.qtz", let QC install it as a Virtual Macro (it prompts for this), then open the demo qtz.
This is excellent. So simple and elegant.
I'll try this in 10.5 too. I've had probs with Virtual Macro's from 10.6 not working correctly in 10.5 before...
Are you saying that multiple word search terms like 'pancake day' would work without needing to enter them as pancake/day, as I'm having to do right now?
Oh no, I didn't mean to infer that. The slash is needed for me as well, when I use multiple words.
Hm, there are a few different issues at play here:
Image Importer
doesn't work inside Iterators in 10.5). The Clip itself doesn't require 10.6.Thanks for clearing that up (10.6), smokris.
"Beefheart" gave me an image that was too Lame to post x10 (the heart of a beef)!
Thanks for listening and responding .
Updated: this clip might actually run on 10.5 now --- apparently 10.5's Javascript patch doesn't include the
JSON
class (while 10.6's does). I added a workaround so that it works on both.Thankyou very much for being in the google index for quartz composer JSON - you saved me a lot of time :D
Here's a slight hack to utilise the ANU Quantum Random Number Server.
After parsing the number is fed to an OSC output for wiring to another app.
Is it possible for this to still work? The URL content isn't passing… is it non-valid, or is this known to not work? I'm trying to do something pretty silly, so it's not particularly pressing, but I'm curious.
@gtoledo3, are you referring to
JSON To Structure Demo.qtz
? Unfortunately, Yahoo shut down their image search API a few years ago, so that particular example won't work anymore.But if you find another search engine API that returns a list of images as JSON, I'd expect
Kineme String With URL
andJSON To Structure
to still work.I see, thanks for the feedback.
Does anyone currently know a good/best way to get some images from the web into qc? I note that coge WebKit seems to do this but it seems to not show gifs in the returned images, and maybe sometimes images that are embedded certain ways? Maybe this is not true for newer versions (that I may not have). I tried the rss w/image importer but was having problems- mainly in finding a valid RSS feed I know has valid images.
Hi,
Do you know if this still works on Sierra (10.12.3)? For me it for some reason doesn't seem to work. I use Kineme HTTP Query to get data from Facebook Graph api, and I do get the JSON, but the /json to structure patch doesn't seem to eat any data.
Does anyone have an alternate way to parse JSON in QC?
I don't know about the KineMe patch but we have developed some other patches for JSON that might be of interest for you:
https://github.com/boinx/QCJSON
Thank you! I actually found your JSON patches earlier today and they gave me hope that JSON parsing is still possible in QC. But unfortunately your patches don't help me as is, because I can't make calls to Facebook Graph Api without sending some query parameters (Access Token, App ID, App Secret). What would be perfect, is a patch that simply takes JSON in and outputs a QC structure.
Here is a sample of the JSON (my latest posts), that FB sends. Parsing this with tools like String Component is a mess.
{"posts":{"data":[{"message":"Minna Canth ja tasa-arvo: kymmenen vuotta yleisen\u00e4 liputusp\u00e4iv\u00e4n\u00e4. \u2764\ud83c\uddeb\ud83c\uddee","created_time":"2017-03-19T11:52:29+0000","id":"10154530412168990_10154595824848990"},{"message":"Toteutimme Ia Enster\u00e4n ja Taija Raution kanssa pikkupikku installaation Lapinlahden sairaalaan. Tule avajaisiin tai k\u00e4y katsomassa kev\u00e4tk\u00e4velyn p\u00e4\u00e4tteeksi joskus my\u00f6hemmin.","story":"Aku Meril\u00e4inen shared Pro Lapinlahti ry's event.","created_time":"2017-03-17T17:14:53+0000","id":"10154530412168990_10154590940023990"}
@incubo, it looks like sometime in the last few years, the behavior of Quartz Composer's JavaScript patch has changed. The QC documentation says:
…but that's no longer accurate — the
_testMode
value is always true; it no longer gets set to false like it used to. So I think you can make it work by changing theif(_testMode)
to something likeif(JSONString)
.By the way, in Vuo we recently added support for JSON and XML parsing, generation, search (content/attribute-based + XPath), and manipulation.
That did the trick – thank you very much!
I really need to start the transition to Vuo for multiple reasons. Perhaps finally after this project. The JSON and XML parsing has been crucial for me and I'm glad to hear that you have implemented it now. You do super work!