naio Posted March 23, 2021 Posted March 23, 2021 (edited) 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, 2021 by naio
comment Posted March 23, 2021 Posted March 23, 2021 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)?
naio Posted March 23, 2021 Author Posted March 23, 2021 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!
comment Posted March 23, 2021 Posted March 23, 2021 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.
naio Posted March 23, 2021 Author Posted March 23, 2021 You're absolutely right, I'm discovering the world of JSONSetElement with brackets, already got rid of that JSONFormatElement... Thank you,
Recommended Posts
This topic is 1332 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now