Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON5 support #331

Open
giacomorebonato opened this issue Apr 21, 2023 · 2 comments
Open

JSON5 support #331

giacomorebonato opened this issue Apr 21, 2023 · 2 comments
Labels
feature Feature request or suggestion

Comments

@giacomorebonato
Copy link

Feature

It would be nice if the project worked also with other more relaxed JSON syntax, like JSON5. What do you think?

Alternative solutions or implementations

I see that jsonc-parser doesn't support JSON5 but jsonc-eslint-parser does and maybe it can be leveraged for unlocking this support.

Other context

Many configuration files are in JSON5 format or exporting just a JS object.
This feature will bring onboard more users interested on using JSON Crack for different reasons.

@giacomorebonato giacomorebonato added the feature Feature request or suggestion label Apr 21, 2023
@AykutSarac
Copy link
Owner

Converting JSON5 to JSON will be easier, but monaco editor doesn't have JSON5 language support from what I've seen so that will be hard. We need to find a way to integrate JSON5 to monaco editor.

@giacomorebonato
Copy link
Author

I am using this configuration, very minimal but OK for my needs:

monaco.languages.register({ id: 'json5' })

monaco.languages.setMonarchTokensProvider('json5', {
    "tokenizer": {
        "root": [
            [/{\s*/, "delimiter.bracket"],
            [/}\s*/, "delimiter.bracket"],
            [/\[/, "delimiter.square"],
            [/\]/, "delimiter.square"],
            [/:\s*/, "delimiter.colon"],
            [/,/, "delimiter.comma"],
            [/true|false|null/, "constant"],
            [/"(?:[^\\\"]|\\.)*"/, "string"],
            [/'(?:[^\\\']|\\.)*'/, "string"],
            [/-?(0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/, "number"],
            [/\/\/.*/, "comment"],
            [/\/\*[\s\S]*?\*\//, "comment"]
        ]
    }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or suggestion
Projects
None yet
Development

No branches or pull requests

2 participants