Skip to content

Show error if JSON is invalid #156

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

Closed
Rich-Harris opened this issue Nov 22, 2017 · 5 comments
Closed

Show error if JSON is invalid #156

Rich-Harris opened this issue Nov 22, 2017 · 5 comments
Labels

Comments

@Rich-Harris
Copy link
Member

Via sveltejs/svelte#938 — if a gist contains invalid JSON, the REPL doesn't appear to mind: https://svelte.technology/repl?version=1.42.0&gist=2afe785004bcdc4c1bcca6f03f2ed7f9

It should show an error instead.

@emirotin
Copy link

The error is shown as I see now, but it's subtle and hard to decipher.
Generally there are 2 or 3 different places where errors are shown, and sometimes it's top of the panel, sometimes as in this case it's at the bottom.

@emirotin
Copy link

I can send a PR that would use https://github.com/json5/json5 instead of vanilla JSON.parse for parsing the json field into data. That will effectively allow writing in the data panel in the same way one would do in normal JS code.

@Rich-Harris
Copy link
Member Author

I agree that this would be better. One thing that concerned me a bit about using JSON5 is that it would be somewhat jarring when the component updates the data, because it would have to stringify the current state in a way that is unlikely to match the user's formatting.

So I whipped up a little module that makes it possible to update the string in place: https://github.com/Rich-Harris/golden-fleece

The idea is that you take a JSON5 string, throw a new object at it, and it will 'patch' the string to add the new values non-destructively. (It isn't at all battle-tested yet!)

A PR would be awesome if you have time! Thank you 😀

@emirotin
Copy link

Heh, nice module. Will try to find time early this (coming) week.
Though IMO having a prettier-like experience with reformat-on-blur would be OK too.

Rich-Harris added a commit that referenced this issue Apr 1, 2018
@Rich-Harris
Copy link
Member Author

this is now implemented

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

No branches or pull requests

2 participants