When using JSON.stringify, I get a lot these errors:
This was driving me crazy, because it seemed to be very random.
You don’t always have a String object , though. So if you try to do that on a string literal, it throws the error above.
Sometimes you can resolve this by first using JSON.parse, but that does not always work either.
The solution is simple: just add an explicit cast to String to your string literal: