Skip to contents

spec_to_json() renders a PlotSpec as a JSON string (via as_spec()); spec_from_json() parses one back into a PlotSpec (via from_spec()). This is the portable wire format for the LLM / agent tooling and the Vega-Lite bridge. See as_spec() for the serializable subset and its guarantees.

Usage

spec_to_json(plot, pretty = TRUE)

spec_from_json(json, data = NULL, env = globalenv())

Arguments

plot

A PlotSpec.

pretty

Whether to pretty-print (default TRUE).

json

A JSON spec string (or a path to a .json file).

data, env

Passed to from_spec() — a data frame for a by-reference spec, and the environment channel expressions are re-quoted in.

Value

spec_to_json() returns a length-1 JSON string; spec_from_json() returns a PlotSpec.

Examples

p <- vplot(mtcars) |> mark_point(x = wt, y = mpg)
json <- spec_to_json(p)
p2 <- spec_from_json(json)