{"id":13609550,"url":"https://github.com/eygraber/jsonapi-kotlin","last_synced_at":"2025-04-23T03:31:50.930Z","repository":{"id":243168857,"uuid":"811666082","full_name":"eygraber/jsonapi-kotlin","owner":"eygraber","description":"A Kotlin Multiplatform kotlinx.serialization library for working with JSON:API","archived":false,"fork":false,"pushed_at":"2024-11-05T19:14:48.000Z","size":236,"stargazers_count":15,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-05T20:28:52.951Z","etag":null,"topics":["json-api","kotlin","kotlin-multiplatform","kotlinx-serialization"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/eygraber.png","metadata":{"files":{"readme":"README.md","changelog":"changelog_config.json","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-07T04:02:23.000Z","updated_at":"2024-11-05T19:14:51.000Z","dependencies_parsed_at":"2024-08-28T20:44:20.575Z","dependency_job_id":"6692be75-8a4b-439b-b714-90145ce10bac","html_url":"https://github.com/eygraber/jsonapi-kotlin","commit_stats":null,"previous_names":["eygraber/jsonapi-kmp","eygraber/jsonapi-kotlin"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eygraber%2Fjsonapi-kotlin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eygraber%2Fjsonapi-kotlin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eygraber%2Fjsonapi-kotlin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eygraber%2Fjsonapi-kotlin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eygraber","download_url":"https://codeload.github.com/eygraber/jsonapi-kotlin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223909861,"owners_count":17223576,"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":["json-api","kotlin","kotlin-multiplatform","kotlinx-serialization"],"created_at":"2024-08-01T19:01:35.874Z","updated_at":"2025-04-23T03:31:50.925Z","avatar_url":"https://github.com/eygraber.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# JSON:API Kotlin\n\n`jsonapi-kotlin` is a Kotlin Multiplatform library for working with [JSON:API](https://jsonapi.org/) documents.\n\nIt integrates with [kotlinx-serialization](https://github.com/Kotlin/kotlinx.serialization) to allow deserializing `String` and `JsonObject` representations of a JSON:API document into a Kotlin type, and for serializing the Kotlin type to a `String` or `JsonObject`.\n\nYou can use this library with all targets supported by [kotlinx-serialization](https://github.com/Kotlin/kotlinx.serialization).\n\n## Gradle\n\n```kotlin\nrepositories {\n  mavenCentral()\n}\n\ndependencies {\n  implementation(\"com.eygraber:jsonapi-kotlin:0.2.3\")\n  \n  // kotlinx.serialization json is used for the actual serialization\n  implementation(\"org.jetbrains.kotlinx:kotlinx-serialization-json:\u003clatest version\u003e\")\n}\n```\n\n## Usage\n\nWith a `kotlinx.serialization.json.Json` instance, you can decode a `JsonApiDocument` from a `String` or `JsonObject`:\n\n```kotlin\nval json = Json()\n\nval document = json.decodeFromString\u003cJsonApiDocument\u003e(string)\n\n// OR\n\nval document = json.decodeFromJsonElement\u003cJsonApiDocument\u003e(jsonObject)\n```\n\nThis will return a generic `JsonApiDocument`. If you know the specific type of `JsonApiDocument` you are working with, you can specify it explicitly so that you don't need to cast:\n\n```kotlin\nval resource = json.decodeFromString\u003cJsonApiDocument.Resource\u003e(string)\nval resources = json.decodeFromString\u003cJsonApiDocument.Resources\u003e(string)\nval resourceIdentifier = json.decodeFromString\u003cJsonApiDocument.Identifier\u003e(string)\nval resourceIdentifiers = json.decodeFromString\u003cJsonApiDocument.Identifiers\u003e(string)\nval meta = json.decodeFromString\u003cJsonApiDocument.Meta\u003e(string)\nval errors = json.decodeFromString\u003cJsonApiDocument.Errors\u003e(string)\n```\n\nYou can also encode the `JsonApiDocument` to a `String` or `JsonObject`:\n\n```kotlin\njson.encodeToString(document)\n\n// OR\n\njson.encodeToJsonElement(document)\n```\n\n## Builders\n\nThere are convenient builder functions available to assist in creating a `JsonApiDocument` from scratch:\n\n```kotlin\nJsonApiDocument\n  .builder()\n  .identifier(\n    type = \"articles\",\n    id = JsonApiId(\"1\"),\n  ) {\n    meta {\n      put(\"created\", \"2019-01-01T00:00:00Z\")\n    }\n  }\n  .build()\n```\n\nSee more examples at [JsonApiBuilderTest](./jsonapi/src/commonTest/kotlin/com/eygraber/jsonapi/JsonApiBuilderTest.kt).\n\n## In Progress\n\nThere is a KSP artifact being worked on that will make it easier to extract your domain types from a `JsonApiDocument`. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feygraber%2Fjsonapi-kotlin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feygraber%2Fjsonapi-kotlin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feygraber%2Fjsonapi-kotlin/lists"}