Malformed JSON
error An error stops the build: nothing is published until it is fixed.
Statac couldn’t read a JSON file in data/. The message says what it found
and points at the place to fix, such as a quote that is never closed or a
comma with nothing after it.
What you’ll see
error Malformed JSON: a comma with nothing after it
Take the comma out.
More: https://statac.dev/e/malformed-json/
In the terminal the message also names the file and line where there is one, and marks the exact text.
Why Statac stops
Past the mistake, Statac can’t tell which values you meant, and templates reaching the file would get the wrong ones, or none, without anyone noticing.
How to fix it
Look at the place the caret points to. JSON is strict, and common causes are:
- A quote or bracket opened and never closed.
- A comma after the last value in a list or an object. JSON allows none.
- A name or text in single quotes, or none. JSON writes both in double quotes.
- A backslash JSON doesn’t know, such as
\q. Write\\for a backslash. - A line break or a tab written as itself inside quotes. Write
\nor\tinstead. - A number written another way, such as
01,.5or+1. Write1,0.5and1.
Example
data/people.json:
[
{"name": "Person 1"},
{"name": "Person 2"},
]
The comma after the last item has nothing after it. Take it out:
[
{"name": "Person 1"},
{"name": "Person 2"}
]
Its name
| Name | malformed-json |
|---|---|
| In the terminal | statac explain malformed-json |
| To stop showing it | It stops the build, so it can't be quietened. |
Something unclear or wrong? Open an issue on GitHub.