Re: Dynamic search for json properties
Re: Dynamic search for json properties
- Subject: Re: Dynamic search for json properties
- From: Rob Lewis <email@hidden>
- Date: Tue, 15 Nov 2016 13:32:35 -0800
Don’t know if this might help, but there is a commercial product called JSON Helper for AppleScript: http://www.mousedown.net/mouseware/JSONHelper.html
I use it for fairly simple stuff and it does what I need.
> On Nov 15, 2016, at 13:24 , email@hidden wrote:
>
> Send AppleScript-Users mailing list submissions to
> email@hidden
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://lists.apple.com/mailman/listinfo/applescript-users
> or, via email, send a message with subject or body 'help' to
> email@hidden
>
> You can reach the person managing the list at
> email@hidden
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of AppleScript-Users digest..."
>
>
> Today's Topics:
>
> 1. Re: Dynamic search for json properties (Jörgen Stahle)
> 2. Re: Dynamic search for json properties (Jörgen Stahle)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 15 Nov 2016 21:14:13 +0000
> From: Jörgen Stahle <email@hidden>
> To: "email@hidden Users"
> <email@hidden>
> Subject: Re: Dynamic search for json properties
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset="utf-8"
>
> Thanks.
>
> I’ve had javascript in mind, but then in the form of Extendscript, since this script is going to run with Indesign server. But the JSON-methods you used here in your Safari example doesn’t work with Extendscript. (And calling Safari is of course not good solution for this use.)
>
> I also tried your javascript code with JSA, but JSON.stringify() doesn’t seem to work there either. Otherwise calling JSA would have been a nice solution.
>
> J
>
>
>
>
> 15 nov. 2016 kl. 18:53 skrev Simon Forster <email@hidden<mailto:email@hidden>>:
>
>
> Cheating but…
>
> Fire up Safari. In the “Develop” menu “Allow JavaScript from Apple Events” then:
>
> tell application "Safari"
> set theString to do JavaScript "var obj = JSON.parse('{\"timeblocksDefs\": { \"normal\": { \"morning\": \"06-09\", \"day\": \"09-18\", \"primetime\": \"18-22\", \"nighttime\": \"22-06\" }, \"lateprime\": { \"morning\": \"06-09\", \"day\": \"09-19\", \"primetime\": \"19-23\", \"nighttime\": \"23-06\" } }}');
> JSON.stringify(obj.timeblocksDefs.lateprime);" in document 1
> end tell
> theString
>
> —> "{\"morning\":\"06-09\",\"day\":\"09-19\",\"primetime\":\"19-23\",\"nighttime\":\"23-06\”}"
>
> Dunno if that helps point you towards a solution to your problem.
>
> All the best
>
> Simon
>
>
>
> On 15 Nov 2016, at 15:20, Jörgen Stahle <email@hidden<mailto:email@hidden>> wrote:
>
> Hi!
>
> I’m an applescripter with no professional knowledge of other programming. And with a bad knowledge of the right terms to use here. Anyway, her is a try to describe my problem
>
> In a current project, I need a script to search a huge json for properties with certain names while ignoring most of the others. The properties are named by their key value, while the script only know this name as a string passed to it as a parameter.
>
> To convert the json into an applescript record, I can use a script library that I once got from Shane Stanley in this forum that (thanks again, Shane!!) But now I want to be able to refer to a certain properties without the need to loop all the json data – since the json is so huge and I have to do that kind of query many times in a time critical situation.
>
>
> So – is there a solution out there that I can use to search dynamically for json properties from applescript?
>
> Simplified example:
>
> I want to be able to ask for the property ”lateprime” among the two properties under ”timeblocksDefs” in the small json below:
>
>
>
> {"timeblocksDefs": {
> "normal": {
> "morning": "06-09",
> "day": "09-18",
> "primetime": "18-22",
> "nighttime": "22-06"
> },
> "lateprime": {
> "morning": "06-09",
> "day": "09-19",
> "primetime": "19-23",
> "nighttime": "23-06"
> }
> }}
>
>
> In my real case, the json is of course far more complicated… Any suggestions welcome!
>
>
>
>
>
>
> <image001.png>
>
> JÖRGEN STAHLE
> Sidproduktionsansvarig
> IT
>
> TT Nyhetsbyrån
> 105 12 Stockholm
> +46 8 691 16 44
> +46 70 372 44 46
> tt.se<http://tt.se/>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden<mailto:email@hidden>)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden<mailto:email@hidden>
>
>
>
>
>
>
> [cid:email@hiddenEF0]
>
> JÖRGEN STAHLE
> Sidproduktionsansvarig
> IT
>
> TT Nyhetsbyrån
> 105 12 Stockholm
> +46 8 691 16 44
> +46 70 372 44 46
> tt.se<http://tt.se/>
>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <https://lists.apple.com/mailman/private/applescript-users/attachments/20161115/df2670f0/attachment.html>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: image001.png
> Type: image/png
> Size: 4536 bytes
> Desc: image001.png
> URL: <https://lists.apple.com/mailman/private/applescript-users/attachments/20161115/df2670f0/attachment.png>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 15 Nov 2016 21:24:11 +0000
> From: Jörgen Stahle <email@hidden>
> To: "email@hidden Users"
> <email@hidden>
> Subject: Re: Dynamic search for json properties
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset="utf-8"
>
> I was wrong! The javascript code DOES work with JSA!
>
> var obj = JSON.parse('{\"timeblocksDefs\": { \"normal\": { \"morning\": \"06-09\", \"day\": \"09-18\", \"primetime\": \"18-22\", \"nighttime\": \"22-06\" }, \"lateprime\": { \"morning\": \"06-09\", \"day\": \"09-19\", \"primetime\": \"19-23\", \"nighttime\": \"23-06\" } }}');
> JSON.stringify(obj.timeblocksDefs.lateprime);
> —> "{\"morning\":\"06-09\",\"day\":\"09-19\",\"primetime\":\"19-23\",\"nighttime\":\"23-06\"}"
>
> Then I just have to call JSA from Applescript. I Guess it is as easy as calling another applescript. (Thanks for the lead, Simon!)
>
> Any thoughts about that, anyone?
>
>
>
>
>
>
>
>
> 15 nov. 2016 kl. 22:14 skrev Jörgen Stahle <email@hidden<mailto:email@hidden>>:
>
> Thanks.
>
> I’ve had javascript in mind, but then in the form of Extendscript, since this script is going to run with Indesign server. But the JSON-methods you used here in your Safari example doesn’t work with Extendscript. (And calling Safari is of course not good solution for this use.)
>
> I also tried your javascript code with JSA, but JSON.stringify() doesn’t seem to work there either. Otherwise calling JSA would have been a nice solution.
>
> J
>
>
>
>
> 15 nov. 2016 kl. 18:53 skrev Simon Forster <email@hidden<mailto:email@hidden>>:
>
>
> Cheating but…
>
> Fire up Safari. In the “Develop” menu “Allow JavaScript from Apple Events” then:
>
> tell application "Safari"
> set theString to do JavaScript "var obj = JSON.parse('{\"timeblocksDefs\": { \"normal\": { \"morning\": \"06-09\", \"day\": \"09-18\", \"primetime\": \"18-22\", \"nighttime\": \"22-06\" }, \"lateprime\": { \"morning\": \"06-09\", \"day\": \"09-19\", \"primetime\": \"19-23\", \"nighttime\": \"23-06\" } }}');
> JSON.stringify(obj.timeblocksDefs.lateprime);" in document 1
> end tell
> theString
>
> —> "{\"morning\":\"06-09\",\"day\":\"09-19\",\"primetime\":\"19-23\",\"nighttime\":\"23-06\”}"
>
> Dunno if that helps point you towards a solution to your problem.
>
> All the best
>
> Simon
>
>
>
> On 15 Nov 2016, at 15:20, Jörgen Stahle <email@hidden<mailto:email@hidden>> wrote:
>
> Hi!
>
> I’m an applescripter with no professional knowledge of other programming. And with a bad knowledge of the right terms to use here. Anyway, her is a try to describe my problem
>
> In a current project, I need a script to search a huge json for properties with certain names while ignoring most of the others. The properties are named by their key value, while the script only know this name as a string passed to it as a parameter.
>
> To convert the json into an applescript record, I can use a script library that I once got from Shane Stanley in this forum that (thanks again, Shane!!) But now I want to be able to refer to a certain properties without the need to loop all the json data – since the json is so huge and I have to do that kind of query many times in a time critical situation.
>
>
> So – is there a solution out there that I can use to search dynamically for json properties from applescript?
>
> Simplified example:
>
> I want to be able to ask for the property ”lateprime” among the two properties under ”timeblocksDefs” in the small json below:
>
>
>
> {"timeblocksDefs": {
> "normal": {
> "morning": "06-09",
> "day": "09-18",
> "primetime": "18-22",
> "nighttime": "22-06"
> },
> "lateprime": {
> "morning": "06-09",
> "day": "09-19",
> "primetime": "19-23",
> "nighttime": "23-06"
> }
> }}
>
>
> In my real case, the json is of course far more complicated… Any suggestions welcome!
>
>
>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <https://lists.apple.com/mailman/private/applescript-users/attachments/20161115/13157542/attachment.html>
>
> ------------------------------
>
> _______________________________________________
> AppleScript-Users mailing list
> email@hidden
> https://lists.apple.com/mailman/listinfo/applescript-users
>
> End of AppleScript-Users Digest, Vol 13, Issue 465
> **************************************************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden