Skip to main content

Processing Array Data in a Script

I have a movie database that I'd like to capture actors from and assign them to the movie. I have JSON data in the array. My goal is to parse it out and create records assigning actors to the movie. Here's some of the steps used to process this:

$array = "{"Actors":"Samuel Ireland, Kylah Day, Melanie Wozniak"}"

Set Variable [ $array ; Value: JSONGetElement (JSON ; "Actors")]

Set Variable [ $count ; Value: ValueCount ( Substitute ( $array ; ", " ; ¶ )

then create a loop in your script and use $count to know how many times you need to loop through the array.

Here was my script (example):

#Set information for actors
Set Variable [ $array; Value:JSONGetElement ( Titles::omdbJSON ; "Actors" ) ]
Set Variable [ $count; Value:ValueCount (
Substitute ( $array ; ", " ; ¶ )
) ]
Set Variable [ $actors; Value:Substitute ( $array ; ", " ; ¶ ) ]
Set Variable [ $movieID; Value:Titles::PrimaryKey ]
#Halt script if array is empty
If [ IsEmpty ( $array ) ]
Halt Script
End If
#Check to see if actor exists if not create actor
Set Variable [ $cnt; Value:1 ]
Loop [ Flush: Always ]
Set Variable [ $temp; Value:GetValue ( $actors ; $cnt