Null
struct NullRepresents JSON null.
Implements Movable, Writable
__init__
def __init__(out self) __str__
def __str__(self) -> String write_to
def write_to[W: Writer](self, mut writer: W) json_mlake · API · value
json.value.valueNullstruct NullRepresents JSON null.
Implements Movable, Writable
__init__def __init__(out self) __str__def __str__(self) -> String write_todef write_to[W: Writer](self, mut writer: W) Valuestruct ValueA JSON value.
Holds either a tape-backed view over a shared Document (what the
parsers produce) or an owned mutable tree (what the constructors and
factories produce, and what a parsed value becomes on first
mutation). See the module header for why both exist; callers use the
same API either way.
The type behaves the way a caller who has met a JSON value in any
other language expects it to: len counts elements or members,
in tests membership, == is a structural deep comparison, a
value may key a Dict, an array iterates, and an object hands back
items() / keys() / values(). Iterable conformance is the one
thing missing: the trait requires an iterator alias parameterized
over the iterable's origin in a shape this compiler cannot spell for
a type whose iterator must also carry a mode, so __iter__ is
defined directly instead. A for loop over a Value works either
way, because the loop resolves __iter__ rather than the trait.
Implements Boolable, Copyable, Equatable, Hashable, Movable, SizedRaising, Writable
__init__def __init__(out self, doc: ArcPointer[Document], tape_idx: Int) Tape-backed view over doc[].tape[tape_idx].
The parser entry point: make_view_value and _make_view_child
both land here, sharing one ArcPointer across every view into
the same document.
def __init__(out self, var owned: OwnedValue) Owned-tree value. Takes ownership; no document is built.
def __init__(out self, null: Null) def __init__(out self, none: NoneType) def __init__(out self, b: Bool) def __init__(out self, i: Int) def __init__(out self, i: Int64) def __init__(out self, f: Float64) def __init__(out self, var s: String) def __init__(out self, u: UInt64) A JSON integer whose magnitude may exceed Int64.MAX.
The unsigned range was readable through is_uint / uint_value
from the day the parser learned to keep it, but no constructor
reached it, so a caller could observe a big integer coming out
of a document and had no way to put an equal one back in.
def __init__(out self, i: Int8) A JSON integer widened from a narrower signed type.
JSON has one number type, so a caller holding an Int8 from
elsewhere in a program should not have to widen it by hand
before it can become a Value.
def __init__(out self, i: Int16) A JSON integer widened from Int16. See Value(Int8).
def __init__(out self, i: Int32) A JSON integer widened from Int32. See Value(Int8).
def __init__(out self, u: UInt8) A JSON integer widened from UInt8. See Value(Int8).
def __init__(out self, u: UInt16) A JSON integer widened from UInt16. See Value(Int8).
def __init__(out self, u: UInt32) A JSON integer widened from UInt32. See Value(Int8).
Widened into the signed range rather than the unsigned one,
because every UInt32 fits Int64 exactly and a value that
answers is_int is the one nearly every caller reaches for.
def __init__(out self, f: Float32) A JSON number widened from Float32.
The widening is the plain one, so a Float32 that cannot name
its decimal literal exactly keeps the error it already had
rather than gaining a different one.
def __init__(out self, var items: List[Self]) A JSON array holding items, in order.
Building {"a":[1,2,3]} used to take a statement per element
plus one for the array and one for the object. This takes the
list a caller already has and moves each element's subtree in,
so nothing is deep-copied on the way.
Example: var a = Value([Value(1), Value(2), Value(3)]).
def __init__(out self, var members: Dict[String, Self]) A JSON object holding members.
Member order follows the Dict's own iteration order, which it
does not promise to be insertion order. Build with
Value.object() plus set when the emitted order matters, or
serialize with sort_keys=True.
Example: var d = DictString, Value d["a"] = Value(1) var o = Value(d^).
__bool__def __bool__(self) -> Bool Whether this value is truthy, the way JSON callers read JSON.
Follows the rule every dynamic language that speaks JSON
settled on: null is false, a boolean is itself, a number is
false only at zero, and a string, array or object is false only
when empty. That makes if doc["items"]: mean "there are
items", which is the test callers actually want to write.
Note this is not is_null() inverted: a present-but-empty
array is false here and not null.
__getitem__def __getitem__(self, index: Int) -> Self Get array element by index.
A negative index counts back from the end, so arr[-1] is the
last element, matching List and matching what a caller
arriving from any other language will try first. Before this,
a negative index raised, which is a poor answer to a question
that has an obvious one.
Example: var arr = loads('[1, 2, 3]') print(arr[0]) # Prints 1. print(arr[-1]) # Prints 3.
index: Array index. Negative counts from the end.def __getitem__(self, key: String) -> Self Get object value by key.
Example: var obj = loads('{"name": "Alice"}') print(obj["name"]) # Prints "Alice".
key: Object key.__setitem__def __setitem__(mut self, key: String, var value: Self) obj["k"] = v, the subscript spelling of set(key, value).
Assignment is how a mapping is written to in every language
this API is read from, and there was no reason for a type whose
reads are already subscripts to make its writes a method call.
Consumes the value, so the common obj["k"] = Value(1) moves
the subtree in rather than copying it.
key: Object key.value: New value to install.Raises Error: If this value is not a JSON object.
def __setitem__(mut self, index: Int, var value: Self) arr[0] = v, the subscript spelling of set(index, value).
A negative index counts back from the end, matching
__getitem__. Only replaces an existing element; use append
to grow the array.
index: Array index. Negative counts from the end.value: New value to install.Raises Error: If this value is not an array, or index names no
element.
__eq__def __eq__(self, other: Self) -> Bool Structural deep equality, as JSON defines sameness.
Two values are equal when they are the same JSON, not when
they serialize to the same text. That distinction is the whole
point: an object's members carry no order, so {"a":1,"b":2}
and {"b":2,"a":1} are one value spelled two ways, and a JSON
number has no type, so 1 and 1.0 are one number spelled two
ways. Comparing text answered no to both, which made ==
unusable for exactly the job callers reached for it to do.
Numbers are compared in the widest domain that holds them
exactly rather than by widening everything to Float64, so two
integers beyond the range a Float64 can name apart stay
apart. A float equals an integer only when it is integral and
converts back to that integer exactly, which is also what keeps
__hash__ in step with this.
Walks the two representations directly instead of materializing either side, so comparing two parsed documents allocates nothing beyond the strings it has to read out of the pools.
__ne__def __ne__(self, other: Self) -> Bool __contains__def __contains__(self, key: String) -> Bool Whether an object has a member named key.
For an array this asks whether some element is that string, so
"a" in loads('["a"]') is true; the two readings cannot
collide, because an array has no members and an object's
members are named by strings rather than held as them.
Anything else contains nothing and answers false rather than
raising, matching what in does in the languages this spelling
comes from.
def __contains__(self, needle: Int) -> Bool Whether an array holds needle, so 3 in arr reads directly.
Present as its own overload because an integer literal does not
become a Value on its own, and Value(3) in arr is a worse
thing to have to write than the test it performs.
def __contains__(self, needle: Self) -> Bool Whether an array holds an element structurally equal to needle.
Equality is Value.__eq__, so member order inside a candidate
element does not matter and Value(1) finds a 1.0. For an
object this tests the member values rather than the names,
since the names are strings and the String overload already
answers those. Anything else answers false.
objectdef object() -> Self An empty JSON object, ready to set into.
Allocation-free, and the intended way to build an object from
scratch. Before this existed the only route to an empty object
was loads("{}") -- a full parser invocation per node.
Example: var o = Value.object() o.set("name", Value("Ada"))
arraydef array() -> Self An empty JSON array, ready to append into.
Allocation-free. See object().
Example: var a = Value.array() a.append(Value(1))
copydef copy(self) -> Self Create a copy of this Value.
A tape view copies for free -- the document lives behind an
ArcPointer, so this is a refcount bump plus the tape index. An
owned tree is deep-copied, giving the copy independent value
semantics.
clonedef clone(self) -> Self Alias for copy(). Creates a deep copy of this Value.
type_namedef type_name(self) -> String The JSON type of this value, spelled as JSON spells it.
Exists so the raising accessors can say what they found rather than only what they wanted, which is the difference between an error a caller can act on and one that sends them back to the document with a print statement.
is_nulldef is_null(self) -> Bool is_booldef is_bool(self) -> Bool is_intdef is_int(self) -> Bool A signed integer that fits Int64.
A magnitude above Int64.MAX answers is_uint instead, so
that a caller reaching for int_value cannot be handed a
wrapped negative number by accident.
is_uintdef is_uint(self) -> Bool An integer above Int64.MAX, readable through uint_value.
is_floatdef is_float(self) -> Bool is_stringdef is_string(self) -> Bool is_arraydef is_array(self) -> Bool is_objectdef is_object(self) -> Bool is_numberdef is_number(self) -> Bool bool_valuedef bool_value(self) -> Bool int_valuedef int_value(self) -> Int64 uint_valuedef uint_value(self) -> UInt64 The value as an unsigned magnitude.
Accepts any integer entry, so a caller that has checked
is_number and wants the widest reading does not have to test
the tag first.
float_valuedef float_value(self) -> Float64 string_valuedef string_value(self) -> String as_booldef as_bool(self) -> Bool This value as a boolean, or an error naming what it is.
Raises Error: If this value is not a JSON boolean.
as_intdef as_int(self) -> Int64 This value as a signed integer, or an error naming what it is.
An integer too large for Int64 answers is_uint rather than
is_int, so it is rejected here instead of being handed back
wrapped into a negative number. Reach for as_uint for those.
Raises Error: If this value is not a signed JSON integer.
as_uintdef as_uint(self) -> UInt64 This value as an unsigned integer, or an error naming what it is.
Accepts either integer tag, because a caller asking for the
unsigned reading of 1 means the same thing whichever range
the parser happened to store it in. A negative integer is
rejected rather than wrapped.
Raises Error: If this value is not a JSON integer, or is negative.
as_floatdef as_float(self) -> Float64 This value as a float, or an error naming what it is.
Accepts any JSON number, not only one that was spelled with a
decimal point. JSON has a single number type, so whether 1 or
1.0 reached the parser is a fact about the text rather than
about the value, and a caller asking for a float would
otherwise have to test three tags before reading a field that
is a number in every document they will ever see.
Raises Error: If this value is not a JSON number.
as_stringdef as_string(self) -> String This value as a string, or an error naming what it is.
Does not stringify a number or a boolean. A caller who wants
the JSON text of any value already has to_json(), and
silently accepting 42 here is what turns a mistyped field
into a bug two layers away.
Raises Error: If this value is not a JSON string.
bool_ordef bool_or(self, default: Bool) -> Bool The boolean this value holds, or default if it holds none.
int_ordef int_or(self, default: Int64) -> Int64 The signed integer this value holds, or default otherwise.
uint_ordef uint_or(self, default: UInt64) -> UInt64 The unsigned integer this value holds, or default otherwise.
Matches as_uint: either integer tag is accepted, and a
negative integer falls back rather than wrapping.
float_ordef float_or(self, default: Float64) -> Float64 The number this value holds as a float, or default otherwise.
Matches as_float: any JSON number is accepted.
string_ordef string_or(self, default: String) -> String The string this value holds, or default if it holds none.
raw_jsondef raw_json(self) -> String pretty_jsondef pretty_json(self, indent: String) -> String This value as indented JSON.
One structural walk with an indent-aware writer, rather than serializing compactly and re-scanning the text.
to_jsondef to_json(self, *, indent: String = String(), ascii_only: Bool = False, escape_solidus: Bool = False, sort_keys: Bool = False) -> String This value as JSON, with serializer options applied.
See _to_json. The two escaping options become parameters
here so the walk that does not use them is the walk that ran
before they existed.
indent: One level of indentation. Empty means compact.ascii_only: Escape every code point above U+007F.escape_solidus: Escape / as \/.sort_keys: Emit object members ordered by key.array_countdef array_count(self) -> Int object_keysdef object_keys(self) -> List[String] object_countdef object_count(self) -> Int __str__def __str__(self) -> String write_todef write_to[W: Writer](self, mut writer: W) __hash__def __hash__[H: Hasher](self, mut hasher: H) Feed this value's digest to hasher.
The Hashable requirement, and the reason a Value may key a
Dict. The digest itself is hash_u64, which is where the
agreement with __eq__ is worked out; this hands the finished
number to whichever hasher the collection chose.
H: The hasher type the collection is using.hasher: The hasher to update.hash_u64def hash_u64(self) -> UInt64 A hash that agrees with __eq__, so a Value can key a Dict.
Agreement is the whole constraint, and it is what dictates the
two unobvious choices here. An object's members carry no order,
so its members' hashes are combined with an operation that does
not care about order; anything order-sensitive would hash
{"a":1,"b":2} and {"b":2,"a":1} into different buckets after
__eq__ has just called them equal. And a number is hashed by
its value rather than by its tag or its bits, so 1, 1.0 and
the same magnitude read out of the unsigned range all land
together.
Hashing a container walks it, so it costs what the subtree
costs. Key a Dict by a scalar where you can.
__len__def __len__(self) -> Int The number of things this value contains.
An array answers its element count and an object its member
count, which is what len means everywhere a JSON value is
used. A string answers its length in bytes, matching
String.byte_length() rather than a count of code points,
because that is the number the rest of this library measures a
string in.
A null, a boolean and a number contain nothing, and they raise
rather than answering 0. Answering 0 would make len(v) == 0
mean two different things, and a caller reaching for len on a
number has usually reached for the wrong field. Use
is_array() / is_object() first if the shape is genuinely
not known.
Raises Error: If this value is a null, a boolean or a number.
getdef get(self, key: String) -> Optional[Self] The member named key, or None when there is no such member.
BREAKING CHANGE in 0.4.0. This used to return the member's raw
JSON text as a String and raise when the key was absent,
which is two surprises at once for a name that every language
with a mapping type gives to the lookup that tolerates a miss.
The old behaviour is still available, under the name that says
what it does: raw_member(key).
A value that is not an object still raises, matching
__getitem__. Only the absent key is answered with None,
because "this document has no such field" is data and "I called
a member lookup on an array" is a bug.
Example: var data = loads('{"name":"Alice"}') var name = data.get("name") if name: print(name.value().string_value()).
key: The member name to look for.Raises Error: If this value is not a JSON object.
def get(self, key: String, default: Self) -> Self The member named key, or default when there is no such member.
The two-argument form of get, for the common shape where the
caller has a fallback ready and does not want to unwrap an
Optional to use it.
Example: var port = config.get("port", Value(8080)).
key: The member name to look for.default: The value to return when the member is absent.Raises Error: If this value is not a JSON object.
raw_memberdef raw_member(self, key: String) -> String The member named key, serialized back to JSON text.
This is what get(key) did before 0.4.0, under a name that
says so. It is a serialization, not a lookup: reading a member
this way and parsing the result costs a full round trip, so
prefer get / __getitem__ and the typed accessors unless the
JSON text itself is what you want.
key: The member name to extract.Raises Error: If this value is not an object, or has no such member.
array_itemsdef array_items(self) -> List[Self] Every element of a JSON array, as a List.
Prefer iterating the value itself. This builds the whole list
before the loop body runs once, so a loop that stops early has
already paid for every element it will not look at, and a large
array costs a second copy of itself. for item in data: walks
the same elements one at a time. Kept because it predates the
iterator and callers hold its result.
Example: var data = loads('[1, "hello", true]') for item in data.array_items(): print(item).
Raises Error if not an array.
object_itemsdef object_items(self) -> List[Tuple[String, Self]] Every member of a JSON object, as a List of pairs.
Prefer items(). This builds the whole list, with a copy of
every key and every member subtree, before the loop body runs
once; items() yields one pair at a time. Kept because it
predates the iterator and callers hold its result.
Example: var data = loads('{"a": 1, "b": 2}') for pair in data.object_items(): var key = pair[0] var value = pair[1] print(key, value).
Raises Error if not an object.
setdef set(mut self, key: String, value: Self) Set or update a value in a JSON object.
Routes through OwnedValue so the in-memory tree stays the
source of truth for the mutation, and every read API on this
value observes it immediately.
The mutation is local to the value it is called on. __getitem__
hands back an independent value rather than a handle into its
parent, so doc["a"].set("b", v) edits a child that doc no
longer shares and doc is unchanged. To write through a parent
chain, name the destination with a JSON Pointer:
doc.set_at("/a/b", v).
Example: var obj = loads('{"name": "Alice"}') obj.set("age", Value(30)) obj.set("name", Value("Bob")) # Update existing.
key: Object key.value: New value to set.def set(mut self, var key: String, var value: Self) set that consumes its arguments.
Selected automatically when the value is a temporary -- the
common o.set("k", Value(1)) shape -- so the subtree is moved
in rather than deep-copied. Mojo resolves this against the
borrowed overload above by argument convention; existing callers
passing a named variable keep the copying behaviour and their
value stays usable.
def set(mut self, index: Int, value: Self) Set a value at an array index.
A negative index counts back from the end, as it does for
__getitem__, so arr.set(-1, v) replaces the last element.
Example:
var arr = loads('[1, 2, 3]')
arr.set(1, Value(20)) # Result is [1, 20, 3].
index: Array index. Negative counts from the end.value: New value to set.def set(mut self, index: Int, var value: Self) set(index, ...) that consumes its value. See set(key, ...).
removedef remove(mut self, key: String) Remove the member named key from an object.
The counterpart to set, which an object had no way to undo:
removing a member meant rebuilding the object member by member,
which is what json/patch.mojo had to do.
key: The member name to remove.Raises Error: If this value is not an object, or has no such
member. Use pop(key, default) shaped code, or test
with key in obj, when absence is expected.
def remove(mut self, index: Int) Remove element index from an array, shifting the rest down.
A negative index counts back from the end, matching
__getitem__.
index: Array index. Negative counts from the end.Raises Error: If this value is not an array, or index names no
element.
popdef pop(mut self, key: String) -> Self Remove the member named key and return its value.
remove when the removed value is not wanted, pop when it
is. The value is moved out of the tree rather than copied, so
popping a large subtree costs no more than popping a scalar.
key: The member name to remove.Raises Error: If this value is not an object, or has no such member.
def pop(mut self, index: Int) -> Self Remove element index from an array and return it.
A negative index counts back from the end, so arr.pop(-1)
takes the last element.
index: Array index. Negative counts from the end.Raises Error: If this value is not an array, or index names no
element.
def pop(mut self) -> Self Remove the last element of an array and return it.
The no-argument form, so using an array as a stack does not need the length computed at the call site.
Raises Error: If this value is not an array, or the array is empty.
__iter__def __iter__(ref self) -> ValueArrayIter[origin_of(self)] Iterate an array's elements, one at a time.
Lazy, unlike array_items(): nothing is built ahead of the
loop, so a loop that stops at the first match pays for what it
looked at and no more. The iterator borrows this value, so the
value has to outlive the loop, which for the usual
for item in doc["items"]: it does.
Example: var data = loads('[1, 2, 3]') for item in data: print(item.int_value()).
Raises Error: If this value is not a JSON array. Iterating an
object is ambiguous enough that it is spelled out:
items(), keys() or values().
itemsdef items(ref self) -> ValueItemsIter[origin_of(self)] Iterate an object's members as (key, value) pairs.
The lazy counterpart to object_items(), which copies every
key and every member subtree before the loop starts. Members
come back in the order the object holds them, which for a
parsed document is document order.
Example: var data = loads('{"a": 1, "b": 2}') for pair in data.items(): print(pair[0], pair[1]).
Raises Error: If this value is not a JSON object.
keysdef keys(ref self) -> ValueKeysIter[origin_of(self)] Iterate an object's member names.
The lazy counterpart to object_keys(), which materializes a
List[String]. Prefer this when the loop only reads the names.
Raises Error: If this value is not a JSON object.
valuesdef values(ref self) -> ValueValuesIter[origin_of(self)] Iterate an object's member values, without their names.
Raises Error: If this value is not a JSON object.
appenddef append(mut self, value: Self) Append a value to a JSON array.
Example:
var arr = loads('[1, 2]')
arr.append(Value(3)) # Result is [1, 2, 3].
value: Value to append.def append(mut self, var value: Self) append that consumes its value.
This is the one that matters for building: appending a freshly built element into a growing array no longer deep-copies the element's whole subtree.
set_atdef set_at(mut self, pointer: String, value: Self) Set a nested value via JSON Pointer (RFC 6901).
Unlike chained __getitem__, this propagates the mutation through the
full parent chain. Intermediate objects/arrays are created or updated
as required by the pointer; missing scalar parents raise.
Example:
var doc = loads('{"a":{"b":1}}')
doc.set_at("/a/b", Value(42)) # Result is {"a":{"b":42}}.
pointer: JSON Pointer string ("" for root, "/a/b" for nested).value: New value to install at pointer.def set_at(mut self, pointer: String, var value: Self) set_at that consumes its value. See set(key, ...).
atdef at(self, pointer: String) -> Self Navigate to a value using JSON Pointer (RFC 6901).
JSON Pointer syntax:
"" (empty) = the whole document.
"/foo" = member "foo" of object.
"/foo/0" = first element of array "foo".
"/a1b" = member "a/b" (/ escaped as n" (~ escaped as ~0).1).
"/m0n" = member "m
Example:
var data = loads('{"users":[{"name":"Alice"}]}')
var name = data.at("/users/0/name") # Value("Alice").
pointer: JSON Pointer string (e.g., "/users/0/name").Raises Error if pointer is invalid or path doesn't exist.
try_atdef try_at(self, pointer: String) -> Optional[Self] The value at pointer, or None if nothing is there.
The twin of at, for the case at handles badly: probing a
document for a field that may or may not be present. at
raises on the first missing segment, so probing meant wrapping
the call in try, which also swallows the errors worth
hearing about.
A pointer that is not a well-formed JSON Pointer still raises,
because that is a mistake in the program rather than a fact
about the document. Only a segment that names nothing, or one
that tries to descend into a scalar, answers None.
Example:
var data = loads('{"a":{"b":1}}')
var hit = data.try_at("/a/b") # Some(Value(1)).
var miss = data.try_at("/a/zz") # None.
pointer: JSON Pointer string. "" names the whole value.Raises Error: If pointer is not a well-formed JSON Pointer.
ValueArrayIterstruct ValueArrayIter[mut: Bool, //, origin: Origin[mut=mut]]Yields the elements of a JSON array, one at a time.
Built by Value.__iter__, so for item in arr: reaches it.
Implements Copyable, Iterator, Movable
comptime Element = Value__init__def __init__(out self, ref[origin] src: Value) Start at the first element of src.
__iter__def __iter__(self) -> Self An iterator is its own iterable.
Present so for pair in obj.items(): reaches the loop
protocol directly, the way a for loop over any other
iterator does.
__has_next__def __has_next__(self) -> Bool Whether any element remains.
__next__def __next__(mut self) -> Value The next element.
ValueItemsIterstruct ValueItemsIter[mut: Bool, //, origin: Origin[mut=mut]]Yields an object's members as (key, value) pairs.
Built by Value.items().
Implements Copyable, Iterator, Movable
comptime Element = Tuple[String, Value]__init__def __init__(out self, ref[origin] src: Value) Start at the first member of src.
__iter__def __iter__(self) -> Self An iterator is its own iterable.
Present so for pair in obj.items(): reaches the loop
protocol directly, the way a for loop over any other
iterator does.
__has_next__def __has_next__(self) -> Bool Whether any member remains.
__next__def __next__(mut self) -> Tuple[String, Value] The next (key, value) pair.
ValueKeysIterstruct ValueKeysIter[mut: Bool, //, origin: Origin[mut=mut]]Yields an object's member names. Built by Value.keys().
Implements Copyable, Iterator, Movable
comptime Element = String__init__def __init__(out self, ref[origin] src: Value) Start at the first member of src.
__iter__def __iter__(self) -> Self An iterator is its own iterable.
Present so for pair in obj.items(): reaches the loop
protocol directly, the way a for loop over any other
iterator does.
__has_next__def __has_next__(self) -> Bool Whether any member remains.
__next__def __next__(mut self) -> String The next member name.
ValueValuesIterstruct ValueValuesIter[mut: Bool, //, origin: Origin[mut=mut]]Yields an object's member values. Built by Value.values().
Implements Copyable, Iterator, Movable
comptime Element = Value__init__def __init__(out self, ref[origin] src: Value) Start at the first member of src.
__iter__def __iter__(self) -> Self An iterator is its own iterable.
Present so for pair in obj.items(): reaches the loop
protocol directly, the way a for loop over any other
iterator does.
__has_next__def __has_next__(self) -> Bool Whether any member remains.
__next__def __next__(mut self) -> Value The next member value.
make_view_valuedef make_view_value(doc: ArcPointer[Document], tape_idx: Int) -> Value Build a tape-backed Value view over doc[].tape[tape_idx].
Thin wrapper around the Value(doc, tape_idx) primary
constructor. Kept as a free function so callers don't need to
spell out the type, and so the construction site reads as
"make a view" rather than "build a Value".
write_valuedef write_value(mut w: JsonWriter, v: Value) Emit v into an existing writer.
The point is the writer: a caller already building a document can
splice a Value into it without the value first becoming its own
String and then being copied in.