March 23, 20214 yr The content of myField is: text before quotes "quoted text" and I want to format a JSON object: JSONFormatElements ( "{\"object\":\"" & myTable::myField & "\"}") the quotes within my data make invalid JSON, so I escape quotes: JSONFormatElements ( "{\"object\":\"" & Substitute ( myTable::myField; "\""; "\\\"") & "\"}") Then I get valid JSON like this: {"object" : "text before quotes \"\u0016quoted text\u0016\""} I wonder where these \u0016 characters added around the quoted text come from, I don't want them there How should I escape quotes without this problem? Edited March 23, 20214 yr by naio
March 23, 20214 yr 20 minutes ago, naio said: where these \u0016 characters added around the quoted text come from Apparently your field contains some invisible control characters . You can test this by checking the result of: Code ( myTable::myField ) for the presence of the string "00022". --- BTW, is there a reason you won't let Filemaker create the JSON object for you by using: JSONSetElement ( "" ; "object" ; myTable::myField ; 1 ) and save yourself the trouble of escaping the quotes (and other special characters)?
March 23, 20214 yr Author Oops! you are right, actually those characters are in the source data but invisible within FM. Regarding the use of JSONSetElement: I think that, for large JSON objects, JSONFormatElements avoids the nesting of several JSONSetElement functions. Anyway I'll consider your advice. Thanks for your help!
March 23, 20214 yr 7 minutes ago, naio said: JSONFormatElements avoids the nesting of several JSONSetElement functions. I don't think so. JSONFormatElements has nothing to do with creating JSON. All it does is look at a string, and if the string is a valid JSON string, it formats it. It doesn't care how the string was created.
March 23, 20214 yr Author You're absolutely right, I'm discovering the world of JSONSetElement with brackets, already got rid of that JSONFormatElement... Thank you,
Create an account or sign in to comment