3 ms·
Basically yes, though `{` and `}` also start and end expression blocks in JavaScript. So the JS formatter needs to be aware that it is working with a JSON objec
by patdx 6y ago
Basically yes, though `{` and `}` also start and end expression blocks in JavaScript. So the JS formatter needs to be aware that it is working with a JSON object and not a complete expression.
Valid JSON:
{
"key1": "hello",
"key2": "world"
}
You could "trick" a JS formatter to format it by wrapping with a fake function, etc. Some minimum valid JS:
json({
key1: "hello",
key2: "world",
});
MongoDB has some JS libraries that use similar tricks to use JS parsers for their shell query format (which is similar to JSON). For example, around line 597: https://unpkg.com/browse/ejson-shell-parser@1.1.1/dist/ejson-shell-parser.cjs.dev.js https://unpkg.com/browse/ejson-shell-parser@1.1.1/dist/ejson...