0

Hello, I'm trying to parse some data using appleScript and JSON helper,
specifically trying to get the value of src of the image property.

 tell application "JSON Helper"
    -- fetch the JSON
    set wallpaperJson to fetch JSON from "https://glowing-torch-5096.firebaseio.com//kimono/api/95cifi2g/latest.json"

    -- pull out the URL
    set wallpaperUrl to src of image of model of results of wallpaperJson

Result,

error "Can’t get image of {{image:{alt:\"April by Rich Cutrone on 500px\", src:\"https://drscdn.500px.org/photo/141047085/q%3D80_h%3D300/fa5a7f61529d6e30a31c04edc63ccdec\"}}}." number -1728 from image of {{image:{alt:"April by Rich Cutrone on 500px", src:"https://drscdn.500px.org/photo/141047085/q%3D80_h%3D300/fa5a7f61529d6e30a31c04edc63ccdec"}}}

Here the source JSON:

{"count":1,"lastrunstatus":"success","name":"500HDPic","newdata":true,"results":{"model":[{"image":{"alt":"April by Rich Cutrone on 500px","src":"https://drscdn.500px.org/photo/141047085/q%3D80_h%3D300/fa5a7f61529d6e30a31c04edc63ccdec"}}]},"thisversionrun":"Mon Feb 22 2016 02:26:31 GMT+0000 (UTC)","thisversionstatus":"success","version":1}

enter image description here

Any help will be very appreciated. Thanks!

1 Answer 1

1

Because the model is a list which contains a record, so the script must get the first item in the model.

Like this:

set wallpaperJson to {thisversionrun:"Mon Feb 22 2016 02:26:31 GMT+0000 (UTC)", |count|:1, results:{model:{{image:{alt:"April by Rich Cutrone on 500px", src:"https://drscdn.500px.org/photo/141047085/q%3D80_h%3D300/fa5a7f61529d6e30a31c04edc63ccdec"}}}}, newdata:true, thisversionstatus:"success", |version|:1, lastrunstatus:"success", |name|:"500HDPic"}

set wallpaperUrl to src of image of item 1 of (model of results of wallpaperJson)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much jackjr300 you are my personal hero. Just wonder why you used the parenthesis.. "(model of results of wallpaperJson)" what that means and where do I need to use it? Thanks you very much for your help and time!
It's just an habit. Sometimes it's necessary, as the selection command of the Finder : item 1 of selectiondoesn't work, item 1 of (get selection) work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.