structToJson doesn't create array
Author: dennis.visschers@sogeti.nl (visschde)
Hi guys, I want to create a message reporting a visit (and potentially more visits in 1 message). The receiving end of this message has defined a API with a visits array that includes one or more visit nodes in JSON, so i made this code to report 1 person visiting:
visits = $newstruct
visits->visits = $newstruct ; i want the root node to be "visits", so i seem to need to do this
visits->visits->visit{1} = $newstruct
visits->visits->visit{1}->guest = $newstruct
visits->visits->visit{1}->guest->customer_number = "%%pers_id.PERSON%%%" ; the receiving API defines this as a string, but i have it as numeric
visits->visits->visit{1}->guest->first_name = firstname.PERSON
visits->visits->visit{1}->guest->surname = name.PERSON
(...)
just for testing and fun i added the following line:
visits->visits->visit{2} = $newstruct
Running all of this code creates a struct that is formed the way i expect it to be, but after executing structToJson on that struct, i noticed that the second visit is just added as a new node at the same level as the first visit. I would have expected the JSON format to look something like this:
"visits" [
"visit": {
"guest" : {
"customer_number" = "1234567890",
"first_name" : "Dennis",
"last_name" : "Visschers"
}
}
"visit" {}
]
Instead i got this:
"visits" {
"visit": {
"guest" : {
"customer_number" = "1234567890",
"first_name" : "Dennis",
"last_name" : "Visschers"
}
}
"visit" {}
}
Is Uniface not capable of creating arrays in JSON? Have i found a bug? Or am i doing something wrong? Thanks for anything you can suggest! :Dennis
by the way: if i omit the asterisk and just tell Uniface to take the first occurrence of the array like this, it compiles!: