0

Are the encodings for JSON and Javascript different? I have a javascript snippet that is embedded in some JSON. However the moment a special character is present in the javascript (e.g. '(' is represented as \x28 in the JS snippet) it causes the JSON to be invalid.

In my example above, only if I update '(' to be represented as '(' instead of '\x28' does it result in valid JSON. The first representation is hex. while the second is valid HTML. I'm not familiar with the encoding types.

Could someone help me understand which encoding I need to use on the Javascript in order to ensure that it always results in the correct format for JSON?

I've included a rough example below. The special characters are '\x28rt' which denotes '(rt'. In JS it gets encoded to \x28rt. However for it to be valid JSON it needs to be ''rt

{
  "class":"myType",
  "id":"testId",
  "javascript":"function testMethod() {var v2 = function (a, b, e) {return e(a,   b);};}var v1 = 'somevalue';if (v2((v1), ('\x28rt'), function (a, b) {if (a == undefined ||  a == null) {return false;}return a === b;})) {alert('test1');};} else   {alert('test2');};}}",
"name":"Step1"
 }
0

1 Answer 1

1

\x28 is the ascii escaping, have you tried Unicode escaping \u0028? http://www.json.org/ says that a char string can have any Unicode character.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.