4 ms·
Rule #2 is "illegal". JSON is actually "JavaScript OBJECT Notation", and raw integers are not "Objects". For compatibilities sake, I'd strongly encourage that
by ramses0 3y ago
Rule #2 is "illegal". JSON is actually "JavaScript OBJECT Notation", and raw integers are not "Objects". For compatibilities sake, I'd strongly encourage that NLD-JSON (New-Line Delimited JSON) contains valid JSON OBJECTS.
Some discussion here: https://stackoverflow.com/questions/17224536/why-is-one-number-valid-json https://stackoverflow.com/questions/17224536/why-is-one-numb...
...I am by no means the harbinger of all things JSON, but it's worth pointing out that this "spec" without addressing the issues that can arise from encouraging "bare" values (not wrapped in []/{}) is highly suspect.
- palotasb 3y agoRaw integers are also valid JSON according to the spec: https://www.json.org/json-en.html https://www.json.org/json-en.html json is defined as one element element is defines as ws (whitespace), value, ws value is defined as one of: object, array, string, number, "true", "false", "null" Wrapping in {} to make an object or in [] to make a list (which is also not an object) is not necessary to make a valid JSON document. This is also discussed in the Stack Overflow question linked.
- cprecioso 3y agoJSON has always accepted "bare" values (try JSON.parse in the browser devtools). In the space, a valid json document is any of those "bare" values, or an array or object of those. All of the answers in your linked StackOverflow also mention this. For example, the spec explainer at https://www.json.org/ https://www.json.org/ (on the righ-hand), tells you that a `json` document is an `element`, which is a `value` surrounded by any or no whitespace. This `value` can be a literal, or an object or array. For an (IMO) easier definition, you can check how JSON values are usually defined in TypeScript e.g. https://github.com/sindresorhus/type-fest/blob/main/source/basic.d.ts#L68 https://github.com/sindresorhus/type-fest/blob/main/source/b...
- lifthrasiir 3y agoThat's only true for older version of specifications (which do NOT include json.org, however). The current RFC 8259 simply defines `json-text` as any allowed value.