3.0.0 #61
tayloraswift
announced in
Announcements
3.0.0
#61
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
swift-jsonv0.3.0 is finally here!obsoleting json dictionary representations
version 0.2 of
swift-jsonmodeled objects (things written in curly braces{}) as dictionaries ofStringkeys andJSONvalues:this is the most obvious representation for a JSON value, it’s convenient for many use cases, and it dovetails nicely with the
JSON.array(_:)enumeration case. however, this representation also comes with some functional and performance issues, so we have replaced this representation with a array-based[(key:String, value:JSON)]representation. this matches APIs vended by Dictionary itself.to convert an object to a
Dictionary, use one of theas(_:uniquingKeysWith:)methods onJSON.ergonomics for high-performance decoding APIs
previously, users of
swift-jsonhad to choose between a slow but ergonomicDecodable-based API, and a fast but extremely verbose direct decoding API.swift-jsonv0.3 comes with a much more ergonomic API for high-performance decoding.to decode objects, you can now use the
LintingDictionaryabstraction, and to decode arrays, you can now useswift-json’sArrayextensions. in addition to being faster, using these decoding interfaces also gives better error diagnostics when decoding fails.for an example of how to use
LintingDictionary, see its associated snippet.RawRepresentableconvenience APIsswift-jsonv0.3 comes with a handful of new convenience APIs for decodingRawRepresentabletypes directly from JSON messages:func `as`<StringCoded>(cases: StringCoded.Type) throws -> StringCodedfunc `as`<CharacterCoded>(cases: CharacterCoded.Type) throws -> CharacterCodedfunc `as`<ScalarCoded>(cases: ScalarCoded.Type) throws -> ScalarCodedfunc `as`<IntegerCoded>(cases: IntegerCoded.Type) throws -> IntegerCodedfunc `as`<UnsignedIntegerCoded>(cases: UnsignedIntegerCoded.Type) throws -> UnsignedIntegerCodedavoid working with
swift-grammardirectlyversion 0.2 of
swift-jsonre-exportedGrammar’s entire API, and expected users to invokeswift-grammarparsing rules directly. this was done to reduce the amount of “magic” in the parser, and guide users towards the lowest-overhead parsing configurations needed for their use case, which was important back whenswift-jsonwas a closed-source library primarily used for fintech applications. however it also made for a very complex API that was hard to learn if you were not already familiar with howswift-grammarworks.version 0.3 of
swift-jsonnow comes with a simplifiedinit(parsing:)initializer, which takes UTF-8-encoded input, and just “does the right thing” by default.ExpressibleBy_Literalconformancesthe
JSONtype now conforms toExpressibleByArrayLiteral,ExpressibleByBooleanLiteral,ExpressibleByDictionaryLiteral,ExpressibleByExtendedGraphemeClusterLiteral,ExpressibleByStringLiteral, andExpressibleByUnicodeScalarLiteral.platform and toolchain support
swift-jsonsupports swift 5.3 ... 5.8 nightly, and has official CI coverage for linux, macOS, iOS, watchOS, tvOS, and windows.swift-jsonhas a fully-green build matrix on the swift package index.documentation
we have expanded
swift-json’s documentation, and published it on swiftinit.This discussion was created from the release 3.0.0.
Beta Was this translation helpful? Give feedback.
All reactions