circlecell / jsonlint.com

[OLD] Please go to new source, link below.

Home Page:https://github.com/circlecell/jsonlint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jsonlint fails on '\.' string

kaze opened this issue · comments

commented

This is invalid json, according to jsonlint:

{"line": "\."}

While this is valid:

{"line": "\\."}

This prevents your json file to contain any regular expression.

commented

see this page for an explanation:
https://stackoverflow.com/questions/19176024/how-to-escape-special-characters-in-building-a-json-string

it refers also to the docs (json.org ):
A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.
a backslash is only allowed when followed by any of these characters: "\/bdnrtu

commented

Honestly, I cannot recall why this was so important to me to leave a note about it. It seems like you just need to double escape all your backslashes when parsing your regexp to JSON, that's all.