Debian Codegraph @

pkg/internal/third_party/go-json-experiment/json/jsontext/doc.go

raw
1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Package jsontext implements syntactic processing of JSON
6 // as specified in RFC 4627, RFC 7159, RFC 7493, RFC 8259, and RFC 8785.
7 // JSON is a simple data interchange format that can represent
8 // primitive data types such as booleans, strings, and numbers,
9 // in addition to structured data types such as objects and arrays.
10 //
11 // The [Encoder] and [Decoder] types are used to encode or decode
12 // a stream of JSON tokens or values.
13 //
14 // # Tokens and Values
15 //
16 // A JSON token refers to the basic structural elements of JSON:
17 //
18 // - a JSON literal (i.e., null, true, or false)
19 // - a JSON string (e.g., "hello, world!")
20 // - a JSON number (e.g., 123.456)
21 // - a begin or end delimiter for a JSON object (i.e., '{' or '}')
22 // - a begin or end delimiter for a JSON array (i.e., '[' or ']')
23 //
24 // A JSON token is represented by the [Token] type in Go. Technically,
25 // there are two additional structural characters (i.e., ':' and ','),
26 // but there is no [Token] representation for them since their presence
27 // can be inferred by the structure of the JSON grammar itself.
28 // For example, there must always be an implicit colon between
29 // the name and value of a JSON object member.
30 //
31 // A JSON value refers to a complete unit of JSON data:
32 //
33 // - a JSON literal, string, or number
34 // - a JSON object (e.g., `{"name":"value"}`)
35 // - a JSON array (e.g., `[1,2,3,]`)
36 //
37 // A JSON value is represented by the [Value] type in Go and is a []byte
38 // containing the raw textual representation of the value. There is some overlap
39 // between tokens and values as both contain literals, strings, and numbers.
40 // However, only a value can represent the entirety of a JSON object or array.
41 //
42 // The [Encoder] and [Decoder] types contain methods to read or write the next
43 // [Token] or [Value] in a sequence. They maintain a state machine to validate
44 // whether the sequence of JSON tokens and/or values produces a valid JSON.
45 // [Options] may be passed to the [NewEncoder] or [NewDecoder] constructors
46 // to configure the syntactic behavior of encoding and decoding.
47 //
48 // # Terminology
49 //
50 // The terms "encode" and "decode" are used for syntactic functionality
51 // that is concerned with processing JSON based on its grammar, and
52 // the terms "marshal" and "unmarshal" are used for semantic functionality
53 // that determines the meaning of JSON values as Go values and vice-versa.
54 // This package (i.e., [jsontext]) deals with JSON at a syntactic layer,
55 // while [encoding/json/v2] deals with JSON at a semantic layer.
56 // The goal is to provide a clear distinction between functionality that
57 // is purely concerned with encoding versus that of marshaling.
58 // For example, one can directly encode a stream of JSON tokens without
59 // needing to marshal a concrete Go value representing them.
60 // Similarly, one can decode a stream of JSON tokens without
61 // needing to unmarshal them into a concrete Go value.
62 //
63 // This package uses JSON terminology when discussing JSON, which may differ
64 // from related concepts in Go or elsewhere in computing literature.
65 //
66 // - a JSON "object" refers to an unordered collection of name/value members.
67 // - a JSON "array" refers to an ordered sequence of elements.
68 // - a JSON "value" refers to either a literal (i.e., null, false, or true),
69 // string, number, object, or array.
70 //
71 // See RFC 8259 for more information.
72 //
73 // # Specifications
74 //
75 // Relevant specifications include RFC 4627, RFC 7159, RFC 7493, RFC 8259,
76 // and RFC 8785. Each RFC is generally a stricter subset of another RFC.
77 // In increasing order of strictness:
78 //
79 // - RFC 4627 and RFC 7159 do not require (but recommend) the use of UTF-8
80 // and also do not require (but recommend) that object names be unique.
81 // - RFC 8259 requires the use of UTF-8,
82 // but does not require (but recommends) that object names be unique.
83 // - RFC 7493 requires the use of UTF-8
84 // and also requires that object names be unique.
85 // - RFC 8785 defines a canonical representation. It requires the use of UTF-8
86 // and also requires that object names be unique and in a specific ordering.
87 // It specifies exactly how strings and numbers must be formatted.
88 //
89 // The primary difference between RFC 4627 and RFC 7159 is that the former
90 // restricted top-level values to only JSON objects and arrays, while
91 // RFC 7159 and subsequent RFCs permit top-level values to additionally be
92 // JSON nulls, booleans, strings, or numbers.
93 //
94 // By default, this package operates on RFC 7493, but can be configured
95 // to operate according to the other RFC specifications.
96 // RFC 7493 is a stricter subset of RFC 8259 and fully compliant with it.
97 // In particular, it makes specific choices about behavior that RFC 8259
98 // leaves as undefined in order to ensure greater interoperability.
99 //
100 // # Security Considerations
101 //
102 // See the "Security Considerations" section in [encoding/json/v2].
103 package jsontext
104
105 // requireKeyedLiterals can be embedded in a struct to require keyed literals.
106 type requireKeyedLiterals struct{}
107
108 // nonComparable can be embedded in a struct to prevent comparability.
109 type nonComparable [0]func()