Updating JSON doc: NDJSON spec deprecated, prefer JSON Lines

This commit is contained in:
Mike Farah 2023-12-01 11:39:02 +11:00
parent 779b26310e
commit a988cd9005
2 changed files with 10 additions and 13 deletions

View File

@ -125,9 +125,7 @@ will output
{"whatever":"cat"} {"whatever":"cat"}
``` ```
## Roundtrip NDJSON ## Roundtrip JSON Lines / NDJSON
Unfortunately the json encoder strips leading spaces of values.
Given a sample.json file of: Given a sample.json file of:
```json ```json
{"this": "is a multidoc json file"} {"this": "is a multidoc json file"}
@ -147,7 +145,7 @@ will output
``` ```
## Roundtrip multi-document JSON ## Roundtrip multi-document JSON
The NDJSON parser can also handle multiple multi-line json documents in a single file! The parser can also handle multiple multi-line json documents in a single file (despite this not being in the JSON Lines / NDJSON spec). Typically you would have one entire JSON document per line, but the parser also supports multiple multi-line json documents
Given a sample.json file of: Given a sample.json file of:
```json ```json
@ -229,7 +227,7 @@ will output
{"a number":4} {"a number":4}
``` ```
## Decode NDJSON ## Decode JSON Lines / NDJSON
Given a sample.json file of: Given a sample.json file of:
```json ```json
{"this": "is a multidoc json file"} {"this": "is a multidoc json file"}

View File

@ -216,15 +216,14 @@ var jsonScenarios = []formatScenario{
scenarioType: "encode", scenarioType: "encode",
}, },
{ {
description: "Roundtrip NDJSON", description: "Roundtrip JSON Lines / NDJSON",
subdescription: "Unfortunately the json encoder strips leading spaces of values.", input: sampleNdJson,
input: sampleNdJson, expected: expectedRoundTripSampleNdJson,
expected: expectedRoundTripSampleNdJson, scenarioType: "roundtrip-ndjson",
scenarioType: "roundtrip-ndjson",
}, },
{ {
description: "Roundtrip multi-document JSON", description: "Roundtrip multi-document JSON",
subdescription: "The NDJSON parser can also handle multiple multi-line json documents in a single file!", subdescription: "The parser can also handle multiple multi-line json documents in a single file (despite this not being in the JSON Lines / NDJSON spec). Typically you would have one entire JSON document per line, but the parser also supports multiple multi-line json documents",
input: sampleMultiLineJson, input: sampleMultiLineJson,
expected: roundTripMultiLineJson, expected: roundTripMultiLineJson,
scenarioType: "roundtrip-multi", scenarioType: "roundtrip-multi",
@ -246,13 +245,13 @@ var jsonScenarios = []formatScenario{
scenarioType: "roundtrip-ndjson", scenarioType: "roundtrip-ndjson",
}, },
{ {
description: "Decode NDJSON", description: "Decode JSON Lines / NDJSON",
input: sampleNdJson, input: sampleNdJson,
expected: expectedNdJsonYaml, expected: expectedNdJsonYaml,
scenarioType: "decode-ndjson", scenarioType: "decode-ndjson",
}, },
{ {
description: "Decode NDJSON, maintain key order", description: "Decode JSON Lines / NDJSON, maintain key order",
skipDoc: true, skipDoc: true,
input: sampleNdJsonKey, input: sampleNdJsonKey,
expected: expectedJsonKeysInOrder, expected: expectedJsonKeysInOrder,