Skip to content

Commit 8b3cc67

Browse files
committed
cmd/cue: prefer ndjson over ldjson
Per ndjson/ndjson-spec#3 in 2014, the ldjson spec (line-delimited JSON) was renamed to ndjson (newline-delimited JSON) and so we should use the newer extension. We already supported loading files with the ndjson extension, but `cue import` still only supported ldjson. Use ndjson in all the documentation and examples, but continue to support ldjson for backwards compatibility. Any non-encoding tests which used ldjson files now use ndjson files for the sake of consistency. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Iff4a853ed5cfc34aaecece523782c4154e3e6e63 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199412 Reviewed-by: Matthew Sackman <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent ecda391 commit 8b3cc67

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

cmd/cue/cmd/help.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ var filetypeHelp = &cobra.Command{
518518
json .json JSON files.
519519
yaml .yaml/.yml YAML files.
520520
toml .toml TOML files
521-
jsonl .jsonl/.ldjson Line-separated JSON values.
521+
jsonl .jsonl/.ndjson Line-separated JSON values.
522522
jsonschema JSON Schema.
523523
openapi OpenAPI schema.
524524
pb Use Protobuf mappings (e.g. json+pb)

cmd/cue/cmd/import.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ more info). This behavior can be overridden by specifying one of
5353
the following modes:
5454
5555
Mode Extensions
56-
json Look for JSON files (.json, .jsonl, .ldjson).
56+
json Look for JSON files (.json .jsonl .ndjson).
5757
yaml Look for YAML files (.yaml .yml).
5858
toml Look for TOML files (.toml).
5959
text Look for text files (.txt).
@@ -269,7 +269,7 @@ Example:
269269

270270
func runImport(cmd *Command, args []string) (err error) {
271271
c := &config{
272-
fileFilter: `\.(json|yaml|yml|toml|jsonl|ldjson)$`,
272+
fileFilter: `\.(json|yaml|yml|toml|jsonl|ndjson|ldjson)$`,
273273
interpretation: build.Auto,
274274
loadCfg: &load.Config{DataFiles: true},
275275
}
@@ -289,7 +289,7 @@ func runImport(cmd *Command, args []string) (err error) {
289289
case "proto":
290290
c.fileFilter = `\.proto$`
291291
case "json":
292-
c.fileFilter = `\.(json|jsonl|ldjson)$`
292+
c.fileFilter = `\.(json|jsonl|ndjson|ldjson)$`
293293
case "yaml":
294294
c.fileFilter = `\.(yaml|yml)$`
295295
case "toml":

cmd/cue/cmd/testdata/script/embed_err.txtar

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ absglob: _ @embed(glob="/x/*.*", type=yaml)
4141

4242
doublestar: _ @embed(glob="**/*.json")
4343

44-
stream: _ @embed(file=test.ldjson)
44+
stream: _ @embed(file=test.ndjson)
4545

46-
singlestream: _ @embed(file=single.ldjson)
46+
singlestream: _ @embed(file=single.ndjson)
4747

4848
yamlstream: _ @embed(file=stream.yaml)
4949

@@ -80,10 +80,10 @@ invalidPattern: _ @embed(glob="x[")
8080

8181
-- test.json --
8282
{ "x": 34 }
83-
-- test.ldjson --
83+
-- test.ndjson --
8484
{ "x": 35 }
8585
{ "x": 36 }
86-
-- single.ldjson --
86+
-- single.ndjson --
8787
{ "x": 37 }
8888
-- stream.yaml --
8989
1

cmd/cue/cmd/testdata/script/encoding_jsonl.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ cmp stdout export-one.stdout
2828

2929
# Check that `cue import` supports all filenames too,
3030
# both by default and when loading JSON only.
31-
# TODO(mvdan): ndjson is not supported here, but it should.
3231
# TODO(mvdan): note that `cue import --dry-run` does not work,
3332
# so we need to use rm and stderr checks to ensure we create the files we expect.
3433

@@ -78,4 +77,5 @@ cmp stderr import.stderr
7877
-- import.stderr --
7978
importing into input-jsonl.cue
8079
importing into input-ldjson.cue
80+
importing into input-ndjson.cue
8181
importing into input-one.cue

cue/interpreter/embed/embed.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
// # Limitations
5555
//
5656
// The embed interpreter currently does not support:
57-
// - stream values, such as .ldjson or YAML streams.
57+
// - stream values, such as .ndjson or YAML streams.
5858
// - schema-based decoding, such as needed for textproto
5959
//
6060
// # Example

0 commit comments

Comments
 (0)