Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

 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 by naio

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)?

  • Author

Oops! :blush3: 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!

 

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.

 

  • 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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.