Trying to create a JSON structure in FileMaker like this:
{
"Cars" : "[VW, GM, Other]",
"First_Name" : "Alan",
"Last_Name" : "Jones"
}
{
"Cars" : "[Ford, Lexus, BMW]",
"First_Name" : "John",
"Last_Name" : "Smith"
}
I've tried two approaches, but both just give me the last JSON element.
Approach 1: (two set variables -- second one overwrites the $$JSON variable - expected result with this approach)
Set Variable [ $$JSON ; Value: JSONSetElement ("{}" ; [ "First_Name" ; "John" ; 0] ; [ "Last_Name" ; "Smith" ; 0 ] ; [ "Cars" ; "[Ford, Lexus, BMW]" ;0] ) ]
Set Variable [ $$JSON ; Value: JSONSetElement ("{}" ; [ "First_Name" ; "Alan" ; 0] ; [ "Last_Name" ; "Jones" ; 0 ] ; [ "Cars" ; "[VW, GM, Other]" ;0] ) ]
Set Field [ Untitled::json ; JSONFormatElements ( $$JSON ) ]
Approach 2: - build in a single Set Variable
Set Variable [ $$JSON ; Value: JSONSetElement ("{}" ; [ "First_Name" ; "John" ; 0] ; [ "Last_Name" ; "Smith" ; 0 ] ; [ "Cars" ; "[Ford, Lexus, BMW]" ;0] ; [ "First_Name" ; "Alan" ; 1] ; [ "Last_Name" ; "Jones" ; 1 ] ; [ "Cars" ; "[VW, GM, Other]" ;1] ) ]
Set Field [ Untitled::json ; JSONFormatElements ( $$JSON ) ]
===
Result:
{
"Cars" : "[VW, GM, Other]",
"First_Name" : "Alan",
"Last_Name" : "Jones"
}
Suggestions?
Thanks,