1

I have this string variable

iteration  = "Toolset\\Iteration 1"

But when I add the string to a JSON.stringify it changes the value adding two more backslashes Toolset\\\\Iteration 1

var data = JSON.stringify([
    {
      "op": "add",
      "path": "/fields/System.IterationPath",
      "value": iteration
    }
]);
//output: Toolset\\\\Iteration 1

I need the output to be Toolset\\Iteration 1

What is the best way of adding that particular string with 2 backslashes to a JSON variable?

1
  • The result you get is Toolset\\\\Iteration 1 Commented May 16, 2021 at 22:21

1 Answer 1

2

JSON stringify encodes the object into a string. The actual value of the JSON is seen after you decode it from the string. The fact that the stringified version has escaped your slashes won't affect the actual value after the decode.

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.