{"id":26426532,"url":"https://github.com/zsqw123/kson","last_synced_at":"2026-04-17T04:33:37.505Z","repository":{"id":57735481,"uuid":"363990914","full_name":"zsqw123/Kson","owner":"zsqw123","description":"A lightweight Kotlin DSL to render DSL style Json to String.","archived":false,"fork":false,"pushed_at":"2021-05-05T08:06:51.000Z","size":106,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-07-04T12:41:45.775Z","etag":null,"topics":["dsl","json","kotlin","serialization"],"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/zsqw123.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":"2021-05-03T16:22:43.000Z","updated_at":"2021-05-05T08:06:53.000Z","dependencies_parsed_at":"2022-08-23T20:30:32.779Z","dependency_job_id":null,"html_url":"https://github.com/zsqw123/Kson","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zsqw123%2FKson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zsqw123%2FKson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zsqw123%2FKson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zsqw123%2FKson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zsqw123","download_url":"https://codeload.github.com/zsqw123/Kson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244151816,"owners_count":20406859,"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":["dsl","json","kotlin","serialization"],"created_at":"2025-03-18T03:33:09.369Z","updated_at":"2025-10-18T16:13:55.477Z","avatar_url":"https://github.com/zsqw123.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Kson\n\n[`简体中文 zh-CN`](./READMECN.MD)\n\n[![Maven Central](https://img.shields.io/maven-central/v/io.github.zsqw123/kson)](https://search.maven.org/artifact/io.github.zsqw123/kson)\n\nA lightweight `Kotlin DSL` to render DSL style `Json` to `String`.\n\nCode: [Kson.kt](https://github.com/zsqw123/Kson/blob/master/src/main/kotlin/Kson.kt)\n\n### DSL\n\n```kotlin\n\nobj{} // empty object\nobj { // object contains key-value\n    \"awa\" - 1\n    \"QwQ\" - false\n    \"\\\"raw\\\":\\\"aaaa\\\"\".raw() // raw json is allowed\n}\narr // empty array\narr[1, \"s\", null] // array with elements\narr[listOf(\"awa\",null,1,false)] // it can provided by any collections\n\n// you can combine these elements whatever you want\narr[\n    1, \n    2,\n    obj {\n        \"awa\" - 1\n        \"QwQ\" - false\n        \"qwq\" - arr[\n            3,\n            4\n        ]\n    }\n]\n```\n\n#### ouputs\n\n```json\n{}\n{\"awa\":1,\"QwQ\":false,\"raw\":\"aaaa\"}\n[]\n[1,\"s\",null]\n[\"awa\",null,1,false]\n[1,2,{\"awa\":1,\"QwQ\":false,\"qwq\":[3,4]}]\n```\n\n#### Pretty outputs\n\nThree methods: `pobj`, `parr`, `pretty`\n\nWhen pass in the `pobj`, all children object `obj`, `arr` will be pretty.\n\nWhen pass in the `parr`, only those who are directly related elements will be pretty, beacuse `parr` not change the namespace, but it is available to use `pretty` wrapper to pretty `arr`.\n\n```kotlin\npobj {\n    obj{\n        \"1\" - arr[\n            arr[\n                obj{\n                    // work well, it will pretty print all children\n                }\n            ]\n        ]\n    }\n}\n\nparr [\n    1,\n    \"awa\", // directly related child will be render\n    arr[ // this arr will not pretty render\n        pobj{\n            // `pobj` change the namespace, so here can be pretty render\n        }\n    ]\n]\n\npretty {\n    arr [ // first arr in `pretty` will be pretty\n        1,\n        \"awa\",\n        arr[\n            // available!\n        ]\n    ]\n}\n```\n\noutput like this:\n\n```json\n{\n    \"awa\":1,\n    \"QwQ\":false,\n    \"qwq\":[\n        3,\n        4\n    ]\n}\n```\n\n### Use\n\n[![Maven Central](https://img.shields.io/maven-central/v/io.github.zsqw123/kson)](https://search.maven.org/artifact/io.github.zsqw123/kson)\n\n```groovy\nimplementation 'io.github.zsqw123:kson:$latest_version'\n```\n\n### Benchmark\n\nBenchmarks have been conducted with the [jmh](https://openjdk.java.net/projects/code-tools/jmh/) OpenJDK tool. Benchmark can be found in [BenchMark.kt](https://github.com/zsqw123/Kson/blob/master/src/test/kotlin/BenchMark.kt)\n\n`Kson` was put side to side with one of the most popular JSON builder for `Java` : [JSON-java](https://github.com/stleary/JSON-java)\n\nTesting environment : *AMD Ryzen 7 4800U, 8 cores 16 threads, VM version: JDK 1.8.0_282, OpenJDK 64-Bit Server VM, 25.282-b08*\n\nScore in operations/second (throughput mode), higher is better\n\n| Benchmark                 | Score     | Error     | Unit  |\n| ------------------------- | --------- | --------- | ----- |\n| jsonWithBigArray          | 15746.152 | ± 524.543 | ops/s |\n| ksonWithBigArray          | 21958.445 | ± 144.323 | ops/s |\n| jsonWithBigArray (Pretty) | 7477.957  | ± 115.563 | ops/s |\n| ksonWithBigArray (Pretty) | 8568.294  | ± 43.227  | ops/s |\n\n#### Thanks\n\n1. This repository inspired by this repo [lectra-tech/koson](https://github.com/lectra-tech/koson), Only reference its api, But the implementation is not same.\n2. Why use `-` ?? Look this:\n\n![](https://cdn.jsdelivr.net/gh/zsqw123/cdn@master/picCDN/20210504144051.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzsqw123%2Fkson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzsqw123%2Fkson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzsqw123%2Fkson/lists"}