One very common use case is that we get the JSON as response from the server than we will convert this to a string and persist
in the protocol. As such, we have to make sure this string is safe in PURE grammar format, i.e. it will escape single quotes
properly since PURE strings are wrapped in a pair of single quotes. The following pair of escape/unescape method does the simple job of
converting a JSON string to/from PURE grammar string
One very common use case is that we get the JSON as response from the server than we will convert this to a string and persist in the protocol. As such, we have to make sure this string is safe in PURE grammar format, i.e. it will escape single quotes properly since PURE strings are wrapped in a pair of single quotes. The following pair of escape/unescape method does the simple job of converting a JSON string to/from PURE grammar string
NOTE: this is slightly different than escaping/unescaping JS string or normal JSON string, this is conversion is actually simplier since the escaping is naturally handling by string conversion in Javascript, we just need to have special handling for the escaping of single-quotes See https://stackoverflow.com/questions/3020094/how-should-i-escape-strings-in-json See https://github.com/joliss/js-string-escape/blob/master/index.js