Alpha Video Training
Results 1 to 4 of 4

Thread: Escaping characters for json

  1. #1
    VAR Pat Bremkamp's Avatar
    Real Name
    Pat Bremkamp
    Join Date
    Apr 2000
    Location
    Oregon, USA
    Posts
    2,618

    Default Escaping characters for json

    We are setting up to start using JSON to store inspection results. I'm excited about creating an inspection history in an array right in the results field. Here is an example of the results field

    [{"when":"2017-11-29 1021","by":1,"source":"F","answer":"All required screens are properly installed."}]

    As you can see it is an array, so the next inspection will have another array element with a later "when" and maybe "by", "source" and "answer", so we will have the history right in the field without a child table. The table I extracted this from has 1.3 million records, so this is a big improvement.

    My concern is the answer. Our inspectors, QC people and engineers are prone to writing whatever they **** well please, so we end up with "can't tell if it's closed" and "the pressure valve (pv1) is not set", and "set to 2/3 capacity" and just about every other character on the keyboard.

    What is the best function for escaping those characters?

    Thanks,
    Pat Bremkamp
    MindKicks Consulting

  2. #2
    VAR Pat Bremkamp's Avatar
    Real Name
    Pat Bremkamp
    Join Date
    Apr 2000
    Location
    Oregon, USA
    Posts
    2,618

    Default Re: Escaping characters for json

    And, how about
    "the pressure valve "pv1" is not set" or "The ratio is 2:1"
    Pat Bremkamp
    MindKicks Consulting

  3. #3
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,665

    Default Re: Escaping characters for json

    Nothing in your first post will cause a problem. It's JSON, the text is double-quoted... so pretty much anything inside is ok... certainly any of your first examples.

    Your second post, untreated, breaks JSON. So... stringify it... which will automatically escape anything that needs it. This code uses static data except for the "Answer"... which is input into a TextBox control. The data input is... the pressure valve "pv1" is not set

    Code:
    var whenData = "2017-11-29";
    var byData = 1;
    var sourceData = "F";
    var answerData = {dialog.Object}.getValue('inputData');
    var listData = JSON.stringify({
    	when: whenData,
    	by: byData,
    	source: sourceData,
    	answer:answerData
    });
    This results in JSON... {"when":"2017-11-29","by":1,"source":"F","answer":"the pressure valve \"pv1\" is not set"}

  4. #4
    VAR Pat Bremkamp's Avatar
    Real Name
    Pat Bremkamp
    Join Date
    Apr 2000
    Location
    Oregon, USA
    Posts
    2,618

    Default Re: Escaping characters for json

    Perfect. Thanks David.
    Pat Bremkamp
    MindKicks Consulting

Similar Threads

  1. escaping quotes in json data
    By Pat Bremkamp in forum Mobile & Browser Applications
    Replies: 10
    Last Post: 11-04-2017, 11:12 AM
  2. TextArea with HTML or JSON ... <JSON Template Data> vs <HTML Memo>
    By CarlMPearson in forum Mobile & Browser Applications
    Replies: 3
    Last Post: 01-20-2016, 12:34 PM
  3. Escaping strings for ADO SQL statements?
    By abackstrom in forum Alpha Five Version 5
    Replies: 6
    Last Post: 02-09-2006, 06:26 PM
  4. Escaping from a query.
    By Steve Pick in forum Alpha Five Version 5
    Replies: 3
    Last Post: 02-03-2003, 08:17 AM
  5. Escaping from containers
    By Martin in forum Alpha Five Version 4
    Replies: 1
    Last Post: 06-18-2002, 09:15 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •