A JSONDecoder extension to allow decoding JSON fragments.
Usage
Simply pass allowFragments: true to a JSONDecoder.decode(_:from:) call, and you’ll be able to decode JSON fragments:
import Foundation
import JSONFragmentDecoding
let data = Data("10".utf8)
let decoded = try JSONDecoder().decode(Int.self, from: data, allowFragments: true)
print(decoded) // 10
Installation
Honestly it’s so lightweight that you could just drop /Sources/JSONFragmentDecoding/JSONFragmentDecoding.swift into your project and be on your way.
Swift PM
Add the following dependancy to your Package.swift file:
JSON Fragment Decoding
A
JSONDecoder
extension to allow decoding JSON fragments.Usage
Simply pass
allowFragments: true
to aJSONDecoder.decode(_:from:)
call, and you’ll be able to decode JSON fragments:Installation
Honestly it’s so lightweight that you could just drop
/Sources/JSONFragmentDecoding/JSONFragmentDecoding.swift
into your project and be on your way.Swift PM
Add the following dependancy to your
Package.swift
file:and then add the dependancy to any targets that need to use it:
Carthage
Add the following to your
Cartfile
: