This Commented CUE demonstrates how to use the cue command to combine multiple JSON files by making reference to the files’ metadata.

The TERMINAL section shows the use of:

  • the --with-context parameter, which makes information about each input file available as metadata
  • the filename metadata field combined with the -l parameter, which places each file’s contents at an individual and deterministic location in the evaluation space
{
    "a": 1,
    "b": 2,
    "c": 3
}
{
    "a": "a string",
    "b": true,
    "c": 42
}
[
    "a list element",
    "another element",
    "the last element"
]
example.cue
package example

// inputs is the location under which we place
// each data file's contents, so that their
// contents can be accessed by the CUE in this
// file. The cue CLI -l parameter places them
// here, under a secondary key determined by each
// file's name.
inputs: [string]: _

output: {
	for _name, _content in inputs {
		(_name): {
			filename: _name
			content:  _content
		}
	}
}
TERMINAL
$ cue export --with-context -l 'inputs:' -l 'path.Base(filename)' -e output a.json b.json c.json example.cue
{
    "a.json": {
        "filename": "a.json",
        "content": {
            "a": 1,
            "b": 2,
            "c": 3
        }
    },
    "b.json": {
        "filename": "b.json",
        "content": {
            "a": "a string",
            "b": true,
            "c": 42
        }
    },
    "c.json": {
        "filename": "c.json",
        "content": [
            "a list element",
            "another element",
            "the last element"
        ]
    }
}