{"id":22828756,"url":"https://github.com/mjmsmith/backspace-json","last_synced_at":"2026-05-16T13:04:37.136Z","repository":{"id":56903420,"uuid":"215623866","full_name":"mjmsmith/backspace-json","owner":"mjmsmith","description":"Stupid simple access for unCodable JSON objects.","archived":false,"fork":false,"pushed_at":"2021-01-16T20:09:55.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-23T18:50:13.823Z","etag":null,"topics":["codable","json","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mjmsmith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-16T19:05:12.000Z","updated_at":"2025-02-24T07:12:35.000Z","dependencies_parsed_at":"2022-08-21T02:50:14.837Z","dependency_job_id":null,"html_url":"https://github.com/mjmsmith/backspace-json","commit_stats":null,"previous_names":["mjmsmith/backspacejson"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mjmsmith/backspace-json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjmsmith%2Fbackspace-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjmsmith%2Fbackspace-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjmsmith%2Fbackspace-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjmsmith%2Fbackspace-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mjmsmith","download_url":"https://codeload.github.com/mjmsmith/backspace-json/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjmsmith%2Fbackspace-json/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266053823,"owners_count":23869496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codable","json","swift"],"created_at":"2024-12-12T19:12:03.019Z","updated_at":"2025-12-12T06:03:26.746Z","avatar_url":"https://github.com/mjmsmith.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BackspaceJSON\n\nCodable has made consuming JSON on iOS much easier, but there are still cases where it's not suitable, such as a configuration file with arbitrary keys and values. In those cases, you just want type-safe access to values without a lot of fuss.\n\nBackspaceJSON is a tiny (single enum, ~100 lines) library written in Swift.\n\n### Initialization\n\n```\ninit(data: Data, options: JSONSerialization.ReadingOptions = .allowFragments) throws\n```\n\nCreate a JSON object from data.\n\n```\nlet json = try JSON(data: data)\n```\n\n### Traversal\n\n```swift\nsubscript(index: Int) -\u003e JSON\nsubscript(key: String) -\u003e JSON\n```\n\nUse string and integer subscripts to traverse any path through the JSON object. Subscripts always return another JSON object, so optional chaining isn't required.\n\n```\njson[\"first\"][0][\"second\"][1]\n```\n\n### Values\n\n```swift\nvar dictionary: [String: JSON]?\nvar array: [JSON]?\nvar string: String?\nvar number: NSNumber?\nvar double: Double?\nvar int: Int?\nvar bool: Bool?\n```\n\nExtract the value from a JSON object using optional properties.\n\n```\njson[\"key\"][0].string\n```\n\n### Existence\n\n```\nvar exists: Bool\nvar existsNull: Bool\nvar existsNotNull: Bool\n```\n\nBackspaceJSON distinguishes between null and missing values.\n\n```\njson[\"one\"][\"two\"].exists        // If true, a value exists at this path (possibly null).\njson[\"one\"][\"two\"].existsNull    // If true, a null value exists at this path.\njson[\"one\"][\"two\"].existsNotNull // If true, a non-null value exists at this path.\n```\n\n### Example\n\nThis code fetches the current version of an app from the App Store.\n\n```\nlet url = URL(string: \"http://itunes.apple.com/lookup?id=\u003cYOUR_APP_ID\u003e\")!\nlet task = URLSession.shared.dataTask(with: url) { data, response, error in\n  guard let data = data,\n        let json = try? JSON(data: data),\n        let currentVersion = json[\"results\"][0][\"version\"].string else {\n    print(\"Lookup failed.\")\n    return\n  }\n\n  print(\"Current version is \\(currentVersion).\")\n}\n\ntask.resume()\n```\n\n### Installation\n\nInstall via CocoaPods:\n\n```\npod \"BackspaceJSON\"\n```\n\nAlternatively, just copy the single file `BackspaceJSON/JSON.swift` into your project.\n\n### License\n\nMIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjmsmith%2Fbackspace-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmjmsmith%2Fbackspace-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjmsmith%2Fbackspace-json/lists"}