Open Classswift 5.10.0Foundation
JSONEncoder
JSONEncoder
facilitates the encoding of Encodable
values into JSON.
class JSONEncoder
Citizens in Foundation
Types
enum DataEncodingStrategy
The strategy to use for encoding
Data
values.enum DateEncodingStrategy
The strategy to use for encoding
Date
values.enum KeyEncodingStrategy
The strategy to use for automatically changing the value of keys before encoding.
enum NonConformingFloatEncodingStrategy
The strategy to use for non-JSON-conforming floating-point values (IEEE 754 infinity and NaN).
struct OutputFormatting
The formatting of the output JSON data.
Type members
init(
) Initializes
self
with default strategies.
Instance members
var dataEncodingStrategy: JSONEncoder.DataEncodingStrategy
The strategy to use in encoding binary data. Defaults to
.base64
.var dateEncodingStrategy: JSONEncoder.DateEncodingStrategy
The strategy to use in encoding dates. Defaults to
.deferredToDate
.var keyEncodingStrategy: JSONEncoder.KeyEncodingStrategy
The strategy to use for encoding keys. Defaults to
.useDefaultKeys
.var nonConformingFloatEncodingStrategy: JSONEncoder.NonConformingFloatEncodingStrategy
The strategy to use in encoding non-conforming numbers. Defaults to
.throw
.var outputFormatting: JSONEncoder.OutputFormatting
The output format to produce. Defaults to
[]
.var userInfo: [CodingUserInfoKey : Any]
Contextual user-provided information for use during encoding.
func encode<T>(T
) throws -> Data Encodes the given top-level value and returns its JSON representation.
Extension in NIOFoundationCompat
Instance members
func encode<T>(T, into: inout ByteBuffer
) throws Writes a JSON-encoded representation of the value you supply into the supplied
ByteBuffer
.func encodeAsByteBuffer<T>(T, allocator: ByteBufferAllocator
) throws -> ByteBuffer Writes a JSON-encoded representation of the value you supply into a
ByteBuffer
that is freshly allocated.
Extension in Basics
Type members
static func makeWithDefaults(prettified: Bool, dateEncodingStrategy: JSONEncoder.DateEncodingStrategy
) -> JSONEncoder static func makeWithDefaults(sortKeys: Bool, prettyPrint: Bool, escapeSlashes: Bool, dateEncodingStrategy: JSONEncoder.DateEncodingStrategy
) -> JSONEncoder
Instance members
Extension in Vapor
Conformances
protocol ContentEncoder
Conform a type to this protocol to make it usable for encoding data via Vapor’s
ContentConfiguration
system.protocol Sendable
A type whose values can safely be passed across concurrency domains by copying.
Type members
static func custom(dates: JSONEncoder.DateEncodingStrategy?, data: JSONEncoder.DataEncodingStrategy?, keys: JSONEncoder.KeyEncodingStrategy?, format: JSONEncoder.OutputFormatting?, floats: JSONEncoder.NonConformingFloatEncodingStrategy?, userInfo: [CodingUserInfoKey : Any]?
) -> JSONEncoder Convenience for creating a customized
JSONEncoder
.
Instance members
func encode<E>(E, to: inout ByteBuffer, headers: inout HTTPHeaders
) throws func encode<E>(E, to: inout ByteBuffer, headers: inout HTTPHeaders, userInfo: [CodingUserInfoKey : Sendable]
) throws