Skip to content

pyld compact

Requires pip install PyLD[cli]

Compact a JSON-LD document using a required context. INPUT accepts a path, URL, or -; CONTEXT accepts a path, URL, or -. Only one operand may read from standard input.

pyld compact --help
Usage: pyld compact [OPTIONS] {INPUT} {CONTEXT}

Compact a JSON-LD document using a context.

╭─ Arguments ──────────────────────────────────────────────────────────────────────────╮
│ * INPUT <str> Path or HTTP(S) URL. Pass - to read from standard input. │
│ [required] │
│ * CONTEXT <str> Context path or URL. Pass - to read JSON from standard │
│ input. │
│ [required] │
╰──────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────────────╮
│ --expand-context <str> Context path or URL. │
│ Pass - to read JSON from │
│ standard input. │
│ --base <str> The base IRI to use. │
│ --extract-all-scripts --no-extract-all-scripts Extract all JSON-LD │
│ script elements from │
│ HTML, or just the first. │
│ --compact-arrays --no-compact-arrays Compact single-value │
│ arrays when appropriate. │
│ --graph --no-graph Always emit a top-level │
│ graph. │
│ --help Show this message and │
│ exit. │
╰──────────────────────────────────────────────────────────────────────────────────────╯

Example

pyld compact docs/examples/data/person.jsonld docs/examples/data/context.jsonld{
"@context": "file:///Users/miel/meemoo/development/pyjsonld/pyld/docs/examples/data/context.jsonld",
"name": "Ada Lovelace"
}

Source person.jsonld

{
  "@context": {
    "name": "http://schema.org/name"
  },
  "name": "Ada Lovelace"
}

Source context.jsonld

{
  "@context": {
    "name": "http://schema.org/name"
  }
}