• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Dynamic search for json properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dynamic search for json properties


  • Subject: Re: Dynamic search for json properties
  • From: Simon Forster <email@hidden>
  • Date: Tue, 15 Nov 2016 17:53:02 +0000


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> 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

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
  • Prev by Date: Re: I'm lost (as usual)
  • Next by Date: Re: Dynamic search for json properties
  • Previous by thread: Re: I'm lost (as usual)
  • Next by thread: Re: Dynamic search for json properties
  • Index(es):
    • Date
    • Thread