Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I have a question regarding writing JSON from MySQL data. For example, I have a STRING column (code) that has a value of [ ] (open and close brackets only), why doesn't tWriteJSONField component enclose the value with double quotes even though the column is declared as STRING? Currently, the JSON output looks like this:
"code":[]
But the expected is:
"code":"[]"
I have already checked the "Quote all values" option in the TWriteJSON component as can be seen in the attached photo.
Thanks!
The open and close square brackets represent an array in JSON. I'll need to know more about the JSON structure and your configuration to understand whether this is meant as a String value of "[]" or whether this has been setup as an array.
Hi @Richard Hall, thank you for your response. It is actually meant to be a String. The value "[]" is a user input which is being successfully saved in the DB as is. The problem occurs when it writes to a JSON, it doesn't recognize the value as a String but an array. See the JSONs below:
Output of tWriteJSON:
[
{
"code":[],
"abbreviation":" ",
"specName":" ",
"showOrder":" ",
"use":"3",
"specCode":"MS ",
"active":true,
"rowId":172,
"visible":true,
"isCodeUpdated":false
}
]
Expected:
[
{
"code":"[]",
"abbreviation":" ",
"specName":" ",
"showOrder":" ",
"use":"3",
"specCode":"MS ",
"active":true,
"rowId":172,
"visible":true,
"isCodeUpdated":false
}
]
We want it to be treated as a String and not an array.
Hmmm, I have tested this and it appears to be a bug caused by the fact that [] is intended to represent arrays. I am raising this as a bug with R&D now. I have found a workaround (which is not ideal, but will work). If you change any String that comes in as "[]" to something unique, like "[bracketreplaceworkaround]", you can produce the JSON with the field typed correctly. Then in a tJavaFlex afterwards you can carry out a String replace, replacing "[bracketreplaceworkaround]" with "[]".
I know this is not ideal at all and I am raising this straight away.