JSON
A container for some UTF-8 encoded JSON source text.
@frozen struct JSON
A container for some UTF-8 encoded JSON source text.
@frozen struct JSON
import JSONAST
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Escapable
protocol Sendable
init(utf8: ArraySlice<UInt8>)
var description: String { get }
var utf8: ArraySlice<UInt8>
@frozen struct Array
A JSON array, which can recursively contain instances of JSON
. This type is a transparent wrapper around a native [JSON]
array.
struct IntegerOverflowError
An integer overflow occurred while converting a number literal to a desired type.
@frozen struct Key
@frozen struct Literal<Value>
@frozen enum Node
@frozen struct Number
A lossless representation of a numeric literal.
@frozen struct Object
A string-keyed JSON object, which can recursively contain instances of JSON
. This type is a transparent wrapper around a native [(key:String, value:JSON)]
array.
@frozen enum TypecastError<Value>
A decoder failed to cast a variant to an expected value type.
import JSONDecoding
protocol TraceableDecoder
A type that represents a scope for decoding operations.
@frozen struct ArrayShape
An efficient interface for checking the length of a decoded array at run time.
@frozen enum ArrayShapeCriteria
What shape you expected an array to have.
@frozen struct ArrayShapeError
An array had an invalid scheme.
@frozen struct DecodingError<Location> where Location : Sendable
An error occurred while decoding a document field.
@frozen struct FieldDecoder<Key> where Key : Sendable
@frozen struct ObjectDecoder<CodingKey> where CodingKey : Hashable, CodingKey : RawRepresentable, CodingKey : Sendable, CodingKey.RawValue == String
A thin wrapper around a native Swift dictionary providing an efficient decoding interface for a JSON object.
@frozen enum ObjectKeyError<CodingKey> where CodingKey : Sendable
An object had an invalid key scheme.
@frozen struct OptionalDecoder<Key> where Key : Sendable
A field that may or may not exist in a document. This type is the return value of ObjectDecoder
’s non-optional subscript, and is useful for obtaining structured diagnostics for “key-not-found” scenarios.
@frozen enum SingleKeyError<CodingKey>
@frozen struct ValueError<Value, Cases> where Value : Sendable
A decoder successfully to cast a variant to an expected value type, but it was not a valid case of the expected destination type.
import JSONLegacy
struct SingleValueDecoder
A single-value decoding container, for use with compiler-generated Decodable
implementations.
import JSONEncoding
static func array(with encode: (inout ArrayEncoder) throws -> Void) rethrows -> JSON
static func array(with encode: (inout ArrayEncoder) async throws -> Void) async rethrows -> JSON
static func object<CodingKey>(encoding keys: CodingKey.Type = CodingKey.self, with encode: (inout ObjectEncoder<CodingKey>) throws -> Void) rethrows -> JSON
mutating func callAsFunction<CodingKey>(_: CodingKey.Type, yield: (inout JSON.ObjectEncoder<CodingKey>) -> ())
@frozen struct ArrayEncoder
@frozen struct ObjectEncoder<Key>
import JSONParsing
struct InvalidUnicodeScalarError
A string literal contained a unicode escape sequence that does not encode a valid Scalar
.
import JSON
Swift JSON is a Foundation-free JSON parser and encoder written in pure Swift. It is designed to be performant, expressive, and speedy to compile.
static func encode<Encodable>(_ value: Encodable) -> JSON where Encodable : JSONEncodable
Creates a raw JSON string by encoding the given instance of Encodable
.
func decode<Decodable>(_ type: Decodable.Type = Decodable.self) throws -> Decodable where Decodable : JSONDecodable
Parses and decodes this raw JSON string as an instance of Decodable
.