XdrJsonValue
public enum XdrJsonValue : Sendable, Equatable
An XDR-JSON document, as defined by SEP-0051.
This is the tree form every XDR type converts to and from. It is deliberately not a
Foundation type: SEP-0051 output places object keys in XDR declaration order, and no
Foundation container preserves that. Dictionary is unordered, and sorting keys
alphabetically is a different order. Making the order a property of the data rather
than of a serializer setting removes the possibility of a non-canonical rendering.
A number is carried as its literal decimal text rather than as a numeric type. XDR-JSON renders 64-bit integers as strings, and the specification’s version 1 compatibility rule allows a JSON number on input; keeping the literal means such a value cannot lose precision by passing through a binary floating-point type.
let tree = XdrJsonValue.object([
XdrJsonMember(key: "min_time", value: .string("0")),
XdrJsonMember(key: "max_time", value: .string("1"))
])
-
A JSON
null. In XDR-JSON this is an absent optional; the key stays present.Declaration
Swift
case null -
A JSON boolean.
Declaration
Swift
case bool(Bool) -
A JSON number, held as the literal decimal text that appears in the document.
Declaration
Swift
case number(String) -
A JSON string.
Declaration
Swift
case string(String) -
A JSON array.
Declaration
Swift
case array([XdrJsonValue]) -
A JSON object, whose members stay in the order they were added.
Declaration
Swift
case object([XdrJsonMember]) -
Whether this value is JSON
null.Declaration
Swift
var isNull: Bool { get } -
The value stored under
key, ornilwhen this is not an object or has no such member. The first member with that key wins; a document parsed byXdrJsonParsercan never contain a duplicate.Declaration
Swift
func member(_ key: String) -> XdrJsonValue? -
The name of this value’s JSON type, as it appears in error messages.
Declaration
Swift
var typeName: String { get }
View on GitHub
Install in Dash