Jump to content

Escaping quotes in JSON data


Recommended Posts

 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
Link to post
Share on other sites
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)?

Link to post
Share on other sites

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!

 

Link to post
Share on other sites
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.

 

Link to post
Share on other sites

You're absolutely right, I'm discovering the world of JSONSetElement with brackets, already got rid of that JSONFormatElement...

Thank you,

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Similar Content

    • By milky
      Hi All,
      Just had a look at the new Add-ons in Fm19.
      Is there a way to make the timer work in reverse.
      i.e. Start from a field (Timer::TimeLength) that a user can input, so that the specified time of say 30:00 will run down to 0:00
      Any help would be appreciated.
      Regards
       
      Milton.
    • By BostonFM
      I am trying to script an import of three worksheets in the same Excel file. The 3 geographical regions worksheets are not structured the same, i.e. field name rows are not in the same place and are named differently.
      The script runs but stops to ask which worksheet to process.
      How do I create a variable/parameter in the script for it to proceed sequentially from worksheet 1-3 without stopping?
      Thanks
      DA
    • By SupportGuys89
      Hello Fellow FM'ers!
      We have been testing Linux and everything has been great, but we are having issues with the authentication via web direct using Windows Federated Services. We followed the steps in the available documentation "Addendum4_ADFS.pdf" and also used "ExtendOAuth_v1.pdf" to get the AD-FS rules configured as well as the necessary admin console requirements (Client Key, Shared Key etc...) We do see the following on attempting to login to our solution:

       
      And when we click on the AD FS Option we do receive a login prompt from our Federated Services:
       

       
      However, even with the correct credentials we still see the following error message:

       
      We have reviewed the logs within AD-FS and no errors are reported and the credentials are passed as expected. Within our solution and Active Directory, we also ensured the user is in the correct group to access our solution via webdirect. I will gladly provide more details into the configuration of AD-FS or FM Admin Console, but these all match the documentation provided by Claris. 
      We went a bit further and got an inhouse developer to take a look and test the flow and he was able to confirm the following:
      Our Endpoints are setup correctly and can be viewed internally @"https://INTERNALADFS/adfs/.well-known/openid-configuration" Initial request  was tested with "https://oidcdebugger.com/"  Postman was then used to test once we received a response. Decoding the jwt received with "https://jwt.ms/"
        The JWT had a unique_name, an email, and a groups array with one of the values in that group array being the group that is set up in the Filemaker solution.   With that said, we are not sure what the next step would be to test this as we appear to be seeing all the correct information in our testing yet we still are not being "authenticated" in our solution. I have also opened a ticket with FIleMaker and no luck as of yet. Any insight would be greatly appreciated!  
    • By Macastronomer
      Thank you in advance...
      We have a serialized field that has a value of FL2021-0001 and increments by +1. 
      I created a script that makes a duplicate record for reasons that don't matter here... but at this point I need to reset the serialized field to the next correct number. I do this with the Set Next Value function as such: 
      Set Next Serial Value [TableFL::SerializedField ; Max ( TableFL::SerializedField ) + 1 ]
      The problem is it sets the next value to 20210002 instead of FL2021-0002.
      Can I read this as a string and increment it or is the return always going to be a strict numeric value?
      Thanks again.
       
    • By Deepak Kumar
      Hello Everyone,
      I would like to check what are issues when FileMaker Pro and Server 19 are installed in Windows Server 2012 R2?
      Thanks.
       
       
       
       
       
×
×
  • Create New...

Important Information

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