JSON problem...[SOLVED]
Posted: Tue May 18, 2021 9:05 am
Hi all,
I've used mailJet's email API for sending users randomised password when they reset their password, and it's worked fine (also great because it's completely free up to a level of sent emails i'll never reach
)
However, I'm having some difficulty construction the JSON required from liveCode arrays. I thought arrayToJSON would do it, but it doesn't seem to create JSON arrays or sub-arrays.
In particular, the message structure required is as below (taken from MailJet's cURL API):
I would have thought creating an array Messages[] and populating Messages[From][Email] for example, and then use arrayToJSON(Messages[]) would do it and superficially it does seem to.
However, very crucially, arrayToJSON doesn't seem to create JSON arrays (the output contains no square brackets, just curly braces that denote JSON objects rather than arrays) and i can't seem to see a way to force arrays, which in this case are required for the API.
I always presume it's likely something i've not done properly when things don't work, and happy to be told i'm doing something wrong! But in this case i wonder if it could be an issue with arrayToJSON?
I could just construct the message bit by bit, but i was hoping for a more elegant solution... any suggestions?
I've used mailJet's email API for sending users randomised password when they reset their password, and it's worked fine (also great because it's completely free up to a level of sent emails i'll never reach

However, I'm having some difficulty construction the JSON required from liveCode arrays. I thought arrayToJSON would do it, but it doesn't seem to create JSON arrays or sub-arrays.
In particular, the message structure required is as below (taken from MailJet's cURL API):
Code: Select all
{"Messages":[
{
"From": {
"Email": "pilot@mailjet.com",
"Name": "Mailjet Pilot"
},
"To": [
{
"Email": "passenger1@mailjet.com",
"Name": "passenger 1"
}
],
"Subject": "Your email flight plan!",
"TextPart": "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
"HTMLPart": "<h3>Dear passenger 1, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!"
}
]
}
However, very crucially, arrayToJSON doesn't seem to create JSON arrays (the output contains no square brackets, just curly braces that denote JSON objects rather than arrays) and i can't seem to see a way to force arrays, which in this case are required for the API.
I always presume it's likely something i've not done properly when things don't work, and happy to be told i'm doing something wrong! But in this case i wonder if it could be an issue with arrayToJSON?
I could just construct the message bit by bit, but i was hoping for a more elegant solution... any suggestions?