Skip to contents

Export a justifier specification to JSON

Usage

export_to_json(x, file = NULL, wrap_in_html = FALSE)

# S3 method for justifierStructuredObject
export_to_json(x, file = NULL, wrap_in_html = FALSE)

# S3 method for justifier_json
print(x, ...)

Arguments

x

The justifier specification.

file

Optionally, a file to save the JSON to.

wrap_in_html

Whether to wrap the JSON in an HTML element.

...

Any additional arguments are ignored.

Value

If a file is specified to write, to, x will be returned invisibly to allow building a pipe chain; if file=NULL, the resulting JSON will be returned as a character vector.

Examples

### Programmatically create a justification with two assertions
### but without sources; flatten it; and show the json
justifier::justify(
  "Icecream will make me feel less fit",
  assertion = c(
    justifier::assert('Icecream is rich in energy'),
    justifier::assert('Consuming high-energy foods makes me feel less fit')
  ),
  weight = -.5
) |>
  justifier::flatten() |>
  justifier::export_to_json();
#> {
#>   "sources": [],
#>   "assertions": {
#>     "pzjt_A7n8bp9qx": {
#>       "id": ["pzjt_A7n8bp9qx"],
#>       "label": ["Icecream is rich in energy"],
#>       "description": [""],
#>       "type": [""],
#>       "source": {}
#>     },
#>     "kvuj_A7n8bp9qx": {
#>       "id": ["kvuj_A7n8bp9qx"],
#>       "label": ["Consuming high-energy foods makes me feel less fit"],
#>       "description": [""],
#>       "type": [""],
#>       "source": {}
#>     }
#>   },
#>   "justifications": {
#>     "dkcn_J7n8bp9qx": {
#>       "id": ["dkcn_J7n8bp9qx"],
#>       "label": ["Icecream will make me feel less fit"],
#>       "description": [""],
#>       "type": [""],
#>       "assertion": ["pzjt_A7n8bp9qx", "kvuj_A7n8bp9qx"],
#>       "weight": [-0.5]
#>     }
#>   },
#>   "decisions": [],
#>   "justifier": []
#> }