{"id":18051609,"url":"https://github.com/kenta-shimizu/json4java8","last_synced_at":"2025-06-29T00:37:33.519Z","repository":{"id":108361772,"uuid":"234544709","full_name":"kenta-shimizu/json4java8","owner":"kenta-shimizu","description":"This library is JSON (RFC8259) parser implementation on Java8. Also supports JSONC reading.","archived":false,"fork":false,"pushed_at":"2023-07-01T16:16:34.000Z","size":385,"stargazers_count":4,"open_issues_count":0,"forks_count":9,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T18:10:58.507Z","etag":null,"topics":["java","java8","json","json-api","json-parser","jsonc","jsonc-parser"],"latest_commit_sha":null,"homepage":"","language":"Java","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/kenta-shimizu.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-17T12:32:22.000Z","updated_at":"2025-01-14T01:38:46.000Z","dependencies_parsed_at":"2024-10-30T22:51:39.115Z","dependency_job_id":"ac73cef2-876e-4792-b1c3-1cab306b2f86","html_url":"https://github.com/kenta-shimizu/json4java8","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/kenta-shimizu/json4java8","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenta-shimizu%2Fjson4java8","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenta-shimizu%2Fjson4java8/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenta-shimizu%2Fjson4java8/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenta-shimizu%2Fjson4java8/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kenta-shimizu","download_url":"https://codeload.github.com/kenta-shimizu/json4java8/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenta-shimizu%2Fjson4java8/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262518105,"owners_count":23323301,"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":["java","java8","json","json-api","json-parser","jsonc","jsonc-parser"],"created_at":"2024-10-30T22:51:08.316Z","updated_at":"2025-06-29T00:37:33.498Z","avatar_url":"https://github.com/kenta-shimizu.png","language":"Java","readme":"# json4java8\n\n## Introduction\n\nThis library is JSON ([RFC8259](https://tools.ietf.org/html/rfc8259)) parser implementation on Java8. Also supports JSONPath, JSONC reading.\n\n## Example of use\n\n```java\npublic class POJO {\n\t\n\tpublic int num;\n\tpublic String str;\n\tpublic boolean bool;\n\tpublic List\u003cString\u003e array;\n\t\n\tpublic POJO() {\n\t\tnum = 100;\n\t\tstr = \"STRING\";\n\t\tbool = true;\n\t\tarray = Arrays.asList(\"a\", \"b\", \"c\");\n\t}\n\t\n\tpublic static void main(String[] args) {\n\n\t\tPOJO pojo = new POJO();\n\t\tString json = JsonHub.fromPojo(pojo).toJson();\n\t\tSystem.out.println(json);\n\n\t\t/* {\"num\":100,\"str\":\"STRING\",\"bool\":true,\"array\":[\"a\",\"b\",\"c\"]} */\n\t}\n}\n```\n\n[Javadoc](https://kenta-shimizu.github.io/json4java8/index.html)\n\n## Convert\n\n1. Create JsonHub instance from `#fromPojo`, `#fromJson`, `#fromFile`, `#fromBytes`.\n1. Convert using `#toPojo`, `#toJson`, `#writeFile`, `#getBytes`, `#writeBytes`.\n\n\n### From POJO (Plain Old Java Objec) to JSON\n\n```java\n/* to String */\nString json = JsonHub.fromPojo(pojo).toJson();\n\n/* to Writer */\nWriter writer = new StringWriter()\nJsonHub.fromPojo(pojo).toJson(writer);\n\n/* to file */\nPath path = Paths.get(\"path/of/file.json\");\nJsonHub.fromPojo(pojo).writeFile(path);\n```\n\n#### From POJO conditions\n\n- Field is `public`\n- Field is *not* `static`\n\nSee also [\"/src/examples/example02/PojoParseToJsonString.java\"](/src/examples/example02/PojoParseToJsonString.java)  \nSee also [\"/src/examples/example03/PojoWriteJsonToFile.java\"](/src/examples/example03/PojoWriteJsonToFile.java)\n\n\n### From JSON to POJO\n\n```java\n/* from JSON String */\nString json = \"{\\\"num\\\": 100, \\\"str\\\": \\\"STRING\\\", \\\"bool\\\": true}\";\nPojo pojo = JsonHub.fromJson(json).toPojo(Pojo.class);\n\n/* from Reader */\nReader reader = new StringReader(json);\nPojo pojo = JsonHub.fromJson(reader).toPojo(Pojo.class);\n\n/* from file */\nPath path = Paths.get(\"path/of/file.json\");\nPojo pojo = JsonHub.fromFile(path).toPojo(Pojo.class);\n```\n\n#### To POJO conditions\n\n- Class has `public new()` (arguments is 0)\n- Field is `public`\n- Field is *not* `static`\n- Field is *not* `final`\n\nSee also [\"/src/examples/example01/JsonStringParseToPojo.java\"](/src/examples/example01/JsonStringParseToPojo.java)  \nSee also [\"/src/examples/example04/ReadJsonFileParseToPojo.java\"](/src/examples/example04/ReadJsonFileParseToPojo.java)\n\n### From POJO to UTF-8 bytes\n\n```java\n/* to bytes */\nbyte[] bytes = JsonHub.fromPojo(pojo).getBytes();\n\n/* to OutputStream */\nOutputStream strm = new ByteArrayOutputStream();\nJsonHub.fromPojo(pojo).writeBytes(strm);\n```\n\n### From UTF-8 bytes to POJO\n\n```java\n/* from bytes */\nbyte[] bytes = json.getBytes(StandardCharsets.UTF_8);\nPojo pojo = JsonHub.fromBytes(bytes).toPojo(Pojo.class);\n\n/* from InputStream */\nInputStream strm = new ByteArrayInputStream(bytes);\nPojo pojo = JsonHub.fromBytes(strm).toPojo(Pojo.class);\n```\n\n## Pretty Print\n\n1. Create JsonHub instance from `#fromPojo`, ...\n1. PrettyPrint using `#prettyPrint`\n\n```java\n/* to String */\nString prettyPrintJson = JsonHub.fromPojo(pojo).prettyPrint();\n\n/* write to file */\nPath path = Paths.get(\"path/of/file.json\");\nJsonHub.fromPojo(pojo).prettyPrint(path);\n\n/* write to Writer */\nWriter writer = new StringWriter();\nJsonHub.fromPojo(pojo).prettyPrint(writer);\n```\n\nSee also [\"/src/examples/example05/PojoParseToPrettyPrintJsonString.java\"](/src/examples/example05/PojoParseToPrettyPrintJsonString.java)  \nSee also [\"/src/examples/example06/PojoWritePrettyPrintJsonToFile.java\"](/src/examples/example06/PojoWritePrettyPrintJsonToFile.java)  \nSee also [\"/src/examples/example09/ChangePrettyPrintFormat.java\"](/src/examples/example09/ChangePrettyPrintFormat.java)\n\n## Get value from JsonHub instance\n\n```java\nString json\n= \"{                                 \"\n+ \"  \\\"num\\\":   100,                 \"\n+ \"  \\\"str\\\":   \\\"STRING\\\",          \"\n+ \"  \\\"bool\\\":  true,                \"\n+ \"  \\\"array\\\": [\\\"a\\\", \\\"b\\\", \\\"c\\\"]\"\n+ \"}                                 \";\n\nJsonHub jh = JsonHub.fromJson(json);\n\nint num = jh.get(\"num\").intValue();  /* 100 */\nString str = jh.get(\"str\").toString();  /* \"STRING\" */\nboolean bool = jh.get(\"bool\").booleanValue();  /* true */\nString array_0 = jh.get(\"array\").get(0).toString();  /* \"a\" */\n```\n\nSee also [\"/src/examples/example08/ForEachJsonHub.java\"](/src/examples/example08/ForEachJsonHub.java)\n\n### Methods for seek value in OBJECT or ARRAY\n\n✓ is available.  \n\"blank\" is throw `JsonHubUnsupportedOperationException`.\n\n| Method | Object | Array | Number | String | true | false | null |\n|:--|:-:|:-:|:-:|:-:|:-:|:-:|:-:|\n|get(CharSequence) | ✓ |  |  |  |  |  |  |  |\n|get(String...)| ✓ |  |  |  |  |  |  |  |\n|get(int)|  | ✓ |  |  |  |  |  |  |  |\n|iterator() | ✓ | ✓ |  |  |  |  |  |\n|stream() | ✓ | ✓ |  |  |  |  |  |\n|forEach(Consumer\u003c? super JsonHub)| ✓ | ✓ |  |  |  |  |  |\n|forEach(BiConsumer\u003c? super JsonString, ? super JsonHub)| ✓ | ✓ |  |  |  |  |  |\n|values() | ✓ | ✓ |  |  |  |  |  |\n|keySet() | ✓ | |  |  |  |  |  |\n|containsKey(CharSequence) | ✓ | |  |  |  |  |  |\n|getOrDefault(CharSequence)| ✓ | |  |  |  |  |  |\n|getOrDefault(CharSequence, JsonHub)| ✓ | |  |  |  |  |  |\n\n### Methods for get value\n\n✓ is available.  \n\"blank\" is throw `JsonHubUnsupportedOperationException`.\n\n| Method | Object | Array | Number | String | true | false | null |\n|:--|:-:|:-:|:-:|:-:|:-:|:-:|:-:|\n|intValue() |  |  | ✓ |  |  |  |  |\n|longValue() |  | | ✓ |  |  |  |  |\n|doubleValue() |  | | ✓ |  |  |  |  |\n|booleanValue() |  | |  |  | ✓ | ✓ |  |\n|optionalInt() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|optionalLong() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|optionalDouble() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|optionalBoolean() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|optionalNumber() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|optionalString() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|length() | ✓ | ✓ |  | ✓ |  |  |  |\n|isEmpty() | ✓ | ✓ |  | ✓ |  |  |  |\n|toString() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n\n### Methods for check type\n\n✓ is available.\n\n| Method | Object | Array | Number | String | true | false | null |\n|:--|:-:|:-:|:-:|:-:|:-:|:-:|:-:|\n|type() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|isObject() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|isArray() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|isNumber() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|isString() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|isTrue() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|isFalse() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|isBoolean() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|isNull() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n|nonNull() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |\n\n## Create JsonHub instance by builder\n\nUse JsonHubBuilder\n\n```java\nJsonHubBuilder jhb = JsonHub.getBuilder();\n\nJsonHub jh = jhb.object(\n    jhb.pair(\"str\", \"STRING\"),\n    jhb.pair(\"num\", 100),\n    jhb.pair(\"bool\", true),\n    jhb.pair(\"array\", jhb.array(\n        jhb.build(\"a\"),\n        jhb.build(\"b\"),\n        jhb.build(\"c\")\n    ))\n);\n\nString json = jh.toJson();\n\nSystem.out.println(json);\n\n/* {\"str\":\"STRING\",\"num\":100,\"bool\":true,\"array\":[\"a\",\"b\",\"c\"]} */\n```\n\nSee also [\"/src/examples/example07/CreateJsonStringByBuilder.java\"](/src/examples/example07/CreateJsonStringByBuilder.java)\n\n## JSONPath\n\nJSONPath is [\"https://goessner.net/articles/JsonPath/\"](https://goessner.net/articles/JsonPath/)\n\n### Supports\n\n| Operator | Description |\n|:--|:--|\n|`$`|The root element.|\n|`*`|Wildcard, all object-name or array-number.|\n|`..`|Recursive descent.|\n|`.\u003cname\u003e`|Child object name operator.|\n|`[\u003cname\u003e(, \u003cname\u003e)]`|Child object name(s) operator.|\n|`[\u003cnumber\u003e(, \u003cnumber\u003e)]`|Child array number(s) operator.|\n|`[start:end:step]`|Child array slice operator.|\n\nNot support `@`, `?()`, `()`\n\n```java\nList\u003cJsonHub\u003e results = jh.jsonPath(\"$.store.book[*].author\");\n```\n\nSee also [\"/src/examples/example11/JsonPath.java\"](/src/examples/example11/JsonPath.java)\n\n## JSONC reading\n\nJSONC (JSON with comments) support.\n\n- /* comment... */\n- // comment...\n- Array trailing comma(,)\n- Object trailing comma(,)\n\n```java\nPath path = Paths.get(\"path/of/file.jsonc\");\nJsonHub jh = JsoncReader.fromFile(path);\nSystem.out.println(jh.prettyPrint());\n```\n\nSee also [\"/src/examples/example10/ReadJsoncFile.java\"](/src/examples/example10/ReadJsoncFile.java)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenta-shimizu%2Fjson4java8","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkenta-shimizu%2Fjson4java8","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenta-shimizu%2Fjson4java8/lists"}