Skip to content

[SR-6163] JSONDecoder cannot decode RFC 7159 JSON #4402

@swift-ci

Description

@swift-ci
Previous ID SR-6163
Radar rdar://problem/38549586
Original Reporter mikkelam (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 23
Component/s Foundation
Labels Bug, Codable
Assignee @itaiferber
Priority Medium

md5: 7ea104c1b9f4df36ef6d428fc2c7cfd0

is duplicated by:

  • SR-7213 Allow JSONEncoder to Encode Top-Level Fragments

relates to:

  • SR-12275 JSONEncoder on Linux can't encode number JSON fragments

Issue Description:

For example

22

Is valid RFC 7159 JSON. This can be parsed using the JSONSerializer like so

let json = "22".data(using: .utf8)!

if let value = (try? JSONSerialization.jsonObject(with: json, options: .allowFragments)) as? Int {
    print(value) // 22
}

But there is no way to use the allowFragments option for JSONDecoder.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions