{"id":30021550,"url":"https://github.com/xn32/json5k","last_synced_at":"2025-08-06T03:03:22.376Z","repository":{"id":61769000,"uuid":"555034460","full_name":"xn32/json5k","owner":"xn32","description":"JSON5 library for Kotlin","archived":false,"fork":false,"pushed_at":"2023-06-26T19:39:21.000Z","size":260,"stargazers_count":18,"open_issues_count":8,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-19T09:42:24.242Z","etag":null,"topics":["json5","kotlin","kotlinx-serialization","parser"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xn32.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-20T20:47:18.000Z","updated_at":"2024-04-25T15:43:50.000Z","dependencies_parsed_at":"2023-02-18T01:16:23.235Z","dependency_job_id":null,"html_url":"https://github.com/xn32/json5k","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/xn32/json5k","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xn32%2Fjson5k","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xn32%2Fjson5k/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xn32%2Fjson5k/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xn32%2Fjson5k/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xn32","download_url":"https://codeload.github.com/xn32/json5k/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xn32%2Fjson5k/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269011132,"owners_count":24344255,"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","status":"online","status_checked_at":"2025-08-06T02:00:09.910Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["json5","kotlin","kotlinx-serialization","parser"],"created_at":"2025-08-06T03:01:50.292Z","updated_at":"2025-08-06T03:03:22.361Z","avatar_url":"https://github.com/xn32.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json5k\n\n[![Build status](https://img.shields.io/github/actions/workflow/status/xn32/json5k/build.yml?branch=main)](https://github.com/xn32/json5k/actions/workflows/build.yml)\n[![codecov](https://codecov.io/gh/xn32/json5k/branch/main/graph/badge.svg?token=PBPA7T92CC)](https://codecov.io/gh/xn32/json5k)\n[![Maven Central](https://img.shields.io/maven-central/v/io.github.xn32/json5k)](https://search.maven.org/artifact/io.github.xn32/json5k/)\n[![Maven Snapshots](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fs01.oss.sonatype.org%2Fcontent%2Frepositories%2Fsnapshots%2Fio%2Fgithub%2Fxn32%2Fjson5k%2Fmaven-metadata.xml\u0026label=snapshots\u0026color=powderblue)](https://s01.oss.sonatype.org/content/repositories/snapshots/io/github/xn32/)\n[![API documentation](https://img.shields.io/badge/docs-Dokka-informational)](https://xn32.github.io/json5k/api/)\n\nThis is an experimental [JSON5](https://json5.org/) library for Kotlin/JVM and Kotlin/Native.\nIt makes use of the [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization) framework to serialize object hierarchies into standard-compliant JSON5 text and vice versa.\n\n## Key features\n\n- Compliance with [v1.0.0](https://spec.json5.org/1.0.0/) of the JSON5 specification\n- Support for polymorphic types and configurable class discriminators\n- Concise error messages for deserialization errors\n- Support for the serialization of comments for class properties\n- Rejection of duplicate keys during deserialization\n\n## Setup instructions\n\njson5k is available on [Maven Central](https://search.maven.org/artifact/io.github.xn32/json5k):\n```kotlin\nplugins {\n    kotlin(\"jvm\") version \"1.8.10\"\n    kotlin(\"plugin.serialization\") version \"1.8.10\"\n}\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation(\"io.github.xn32:json5k:0.3.0\")\n}\n```\n\nOfficial versions are published for the following targets:\n- Java Virtual Machine: `jvm`\n- x86-64 platforms: `linuxX64`, `macosX64`, `iosX64`, `mingwX64`\n- Apple Silicon platforms: `macosArm64`, `iosArm64`, `iosSimulatorArm64`\n\nSnapshot versions of the `main` branch are available from [here](https://s01.oss.sonatype.org/content/repositories/snapshots/io/github/xn32/).\n\n## Usage examples\n\n### Non-hierarchical values\n\n```kotlin\nimport io.github.xn32.json5k.Json5\nimport kotlinx.serialization.decodeFromString\nimport kotlinx.serialization.encodeToString\n\n// Serialization:\nJson5.encodeToString(5142) // 5142\nJson5.encodeToString(listOf(4.5, 1.5e2, 1.2e15)) // [4.5,150.0,1.2E15]\nJson5.encodeToString(mapOf(\"a\" to 10, \"b\" to 20)) // {a:10,b:20}\nJson5.encodeToString(Double.NEGATIVE_INFINITY) // -Infinity\nJson5.encodeToString\u003cInt?\u003e(null) // null\n\n// Deserialization:\nJson5.decodeFromString\u003cInt?\u003e(\"113\") // 113\nJson5.decodeFromString\u003cList\u003cDouble\u003e\u003e(\"[1.2, .4]\") // [1.2, 0.4]\nJson5.decodeFromString\u003cMap\u003cString, Int\u003e\u003e(\"{ a: 10, 'b': 20, }\") // {a=10, b=20}\nJson5.decodeFromString\u003cDouble\u003e(\"+Infinity\") // Infinity\nJson5.decodeFromString\u003cInt?\u003e(\"null\") // null\n\n// Deserialization errors:\nJson5.decodeFromString\u003cByte\u003e(\"190\")\n    // UnexpectedValueError: signed integer in range [-128..127] expected at position 1:1\nJson5.decodeFromString\u003cList\u003cDouble\u003e\u003e(\"[ 1.0,,\")\n    // CharError: unexpected character ',' at position 1:7\n```\n\n### Serializable classes\n\n```kotlin\nimport io.github.xn32.json5k.Json5\nimport kotlinx.serialization.Serializable\nimport kotlinx.serialization.decodeFromString\nimport kotlinx.serialization.encodeToString\n\n@Serializable\ndata class Person(val name: String, val age: UInt? = null)\n\n// Serialization:\nJson5.encodeToString(Person(\"John\", 31u)) // {name:\"John\",age:31}\nJson5.encodeToString(Person(\"Jane\")) // {name:\"Jane\"}\n\n// Deserialization:\nJson5.decodeFromString\u003cPerson\u003e(\"{ name: 'Carl' }\") // Person(name=Carl, age=null)\nJson5.decodeFromString\u003cPerson\u003e(\"{ name: 'Carl', age: 42 }\") // Person(name=Carl, age=42)\n\n// Deserialization errors:\nJson5.decodeFromString\u003cPerson\u003e(\"{ name: 'Carl', age: 42, age: 10 }\")\n    // DuplicateKeyError: duplicate key 'age' at position 1:26\n```\n\n### Classes with `@SerialName` annotations\n\n```kotlin\nimport io.github.xn32.json5k.Json5\nimport kotlinx.serialization.SerialName\nimport kotlinx.serialization.Serializable\nimport kotlinx.serialization.decodeFromString\nimport kotlinx.serialization.encodeToString\n\n@Serializable\ndata class IntWrapper(@SerialName(\"integer\") val int: Int)\n\n// Serialization:\nJson5.encodeToString(IntWrapper(10)) // {integer:10}\n\n// Deserialization:\nJson5.decodeFromString\u003cIntWrapper\u003e(\"{ integer: 10 }\") // IntWrapper(int=10)\n\n// Deserialization errors:\nJson5.decodeFromString\u003cIntWrapper\u003e(\"{ int: 10 }\")\n    // UnknownKeyError: unknown key 'int' at position 1:3\n```\n\n### Polymorphic types\n\n```kotlin\nimport io.github.xn32.json5k.ClassDiscriminator\nimport io.github.xn32.json5k.Json5\nimport kotlinx.serialization.SerialName\nimport kotlinx.serialization.Serializable\nimport kotlinx.serialization.decodeFromString\nimport kotlinx.serialization.encodeToString\n\n@Serializable\n@ClassDiscriminator(\"mode\")\nsealed interface Producer\n\n@Serializable\n@SerialName(\"numbers\")\ndata class NumberProducer(val init: UInt) : Producer\n\n// Serialization:\nJson5.encodeToString\u003cProducer\u003e(NumberProducer(10u)) // {mode:\"numbers\",init:10}\n\n// Deserialization:\nJson5.decodeFromString\u003cProducer\u003e(\"{ init: 0, mode: 'numbers' }\") // NumberProducer(init=0)\n\n// Deserialization errors:\nJson5.decodeFromString\u003cProducer\u003e(\"{ init: 0 }\")\n    // MissingFieldError: missing field 'mode' in object at position 1:1\n```\n\n### Serialization of comments for class properties\n\n```kotlin\nimport io.github.xn32.json5k.Json5\nimport io.github.xn32.json5k.SerialComment\nimport kotlinx.serialization.Serializable\nimport kotlinx.serialization.encodeToString\n\n@Serializable\ndata class Person(\n    val name: String,\n    val age: UInt? = null\n)\n\n@Serializable\ndata class Event(\n    @SerialComment(\"First day of the event\")\n    val date: String,\n    @SerialComment(\"Registered attendees\")\n    val attendees: List\u003cPerson\u003e\n)\n\nval json5 = Json5 {\n    prettyPrint = true\n}\n\nprintln(\n    json5.encodeToString(\n        Event(\"2022-10-04\", listOf(Person(\"Emma\", 31u)))\n    )\n)\n```\n\nRunning this code will produce the following output:\n```\n{\n    // First day of the event\n    date: \"2022-10-04\",\n    // Registered attendees\n    attendees: [\n        {\n            name: \"Emma\",\n            age: 31\n        }\n    ]\n}\n```\n\n### Configuration options\n\nControl generated JSON5 output as follows:\n```kotlin\nimport io.github.xn32.json5k.Json5\nimport kotlinx.serialization.Serializable\nimport kotlinx.serialization.encodeToString\n\nval json5 = Json5 {\n    prettyPrint = true\n    indentationWidth = 2\n    useSingleQuotes = true\n    quoteMemberNames = true\n    encodeDefaults = true\n}\n\n@Serializable\ndata class Person(val name: String, val age: UInt? = null)\n\nprintln(json5.encodeToString(Person(\"Oliver\")))\n```\nThis will result in the following output:\n```\n{\n  'name': 'Oliver',\n  'age': null\n}\n```\n\n### Further examples\n\nSee the unit tests for [serialization](src/commonTest/kotlin/io/github/xn32/json5k/binding/SerializationTest.kt)\nand [deserialization](src/commonTest/kotlin/io/github/xn32/json5k/binding/DeserializationTest.kt) for more examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxn32%2Fjson5k","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxn32%2Fjson5k","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxn32%2Fjson5k/lists"}