Import Json into Numbers

Last year I was guided fromsome awesome ppl here into an AppleScript that helped me paste information from an XML into my Numbers document. Unfortunatly, the xml is no longer pulling new data.


settgtTable to "NFL Scores" -- change if needed to match table name

setpasteCell to "B2" -- upper left cell of range to place values


set txt to do shell script "curl -s " & "http://www.nfl.com/liveupdate/scorestrip/ss.xml"


set pasteStr to ""

repeat with p in txt's paragraphs

set lineTxt to p's text

if lineTxt starts with " <g " then ¬

set pasteStrtopasteStr & ¬

getVal(lineTxt, "h=") & tab ¬

& getVal(lineTxt, "hs=") & tab ¬

& getVal(lineTxt, "v=") & tab ¬

& getVal(lineTxt, "vs=") & return

end repeat

set the clipboard topasteStr


tell application "Numbers"

tell front document'sactive sheet'stabletgtTable to set selection rangetorangepasteCell


activate


delay 0.2 -- vary this if needed

end tell

tell application "System Events" to keystroke"v" using {option down, shift down, command down}


togetVal(t, valTag)

set text item delimiterstovalTag

set val to t's text item 2's first word

endgetVal



I have found another option, but it’s .Json And I’m unsure if this would work in the way my previous one worked.


http://www.nfl.com/liveupdate/scores/scores.json


i was hoping someone could shed some light on this, thx

iPhone 6s Plus, iOS 10.0.1

Posted on Sep 7, 2018 10:41 AM

Reply
4 replies

Sep 8, 2018 11:34 AM in response to SGIII

When I used =ImportJson in Google sheets the data looked like this:

User uploaded file


I adjusted my script once more and got some actual results to work (sort of) It just appeared very different in Numbers compared to how it did in Sheets. I was going to pull only the columns I need in a helper table. Picture below updated Applescript

set tgtTable to "Copy/Paste" -- change if needed to match table name

set pasteCell to "a1" -- upper left cell of range to place values


tell application "JSON Helper"

set myRecord to fetch JSON from "http://www.nfl.com/liveupdate/scores/scores.json"


set the clipboard to (make JSON frommyRecord)

end tell


tell application "Numbers"

tell front document'sactive sheet'stabletgtTable to set selection range to rangepasteCell


activate


delay 0.2 -- vary this if needed

end tell

tell application "System Events" to keystroke "v" using {option down, shift down, command down}


to getVal(t, valTag)

set text item delimiters to valTag

set item2 to t's text item 2

set text item delimiters to "\" "

set val to item2's first text item

end getVal


User uploaded file

W

Sep 8, 2018 8:20 AM in response to SGIII

Hi,

I adjusted my script and was going to post a new question as I'm running into an error still. I see my results in AppleScript bottom portion "Results" but I still can't get the data to post into Numbers.

set tgtTable to "Copy/Paste" -- change if needed to match table name

set pasteCell to "a1" -- upper left cell of range to place values


tell application "JSON Helper"

set myRecord to fetch JSON from "http://www.nfl.com/liveupdate/scores/scores.json"

return myRecord

end tell


tell application "Numbers"

tell front document'sactive sheet'stabletgtTable to set selection range to rangepasteCell


activate


delay 0.2 -- vary this if needed

end tell

tell application "System Events" to keystroke "v" using {option down, shift down, command down}


to getVal(t, valTag)

set text item delimiters to valTag

set item2 to t's text item 2

set text item delimiters to "\" "

set val to item2's first text item

end getVal

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Import Json into Numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.