{"id":35131236,"url":"https://github.com/hudeany/json","last_synced_at":"2026-04-03T22:04:53.018Z","repository":{"id":65959533,"uuid":"88793041","full_name":"hudeany/json","owner":"hudeany","description":"Java JsonReader, JsonWriter, YamlReader, YamlWriter and JsonSchema","archived":false,"fork":false,"pushed_at":"2026-01-18T13:20:16.000Z","size":1191,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-18T15:56:26.532Z","etag":null,"topics":["json","json-parser","json-schema","yaml","yaml-parser"],"latest_commit_sha":null,"homepage":"","language":"Java","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/hudeany.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-04-19T21:36:04.000Z","updated_at":"2026-01-18T13:16:19.000Z","dependencies_parsed_at":"2024-01-04T17:51:32.805Z","dependency_job_id":"8d40d9ae-1115-449d-b22c-e0c9a60a4901","html_url":"https://github.com/hudeany/json","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/hudeany/json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudeany%2Fjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudeany%2Fjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudeany%2Fjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudeany%2Fjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hudeany","download_url":"https://codeload.github.com/hudeany/json/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudeany%2Fjson/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28668305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T17:07:18.858Z","status":"ssl_error","status_checked_at":"2026-01-22T17:05:02.040Z","response_time":144,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["json","json-parser","json-schema","yaml","yaml-parser"],"created_at":"2025-12-28T05:14:45.358Z","updated_at":"2026-02-14T12:04:19.356Z","avatar_url":"https://github.com/hudeany.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Java JsonReader, JsonWriter, YamlReader, YamlWriter and JsonSchema\n\nRead and write JSON and YAML data from and to files or streams.  \nValidation by JsonSchema (see http://json-schema.org for specifications).  \nSequential read of JsonArray and YamlSequence items (like SAX parser for XML data).  \n\n## JsonObject with JsonWriter and JsonReader example\n```\nJsonWriter writer = null;\nByteArrayOutputStream output = null;\nJsonReader reader = null;\ntry {\n\toutput = new ByteArrayOutputStream();\n\twriter = new JsonWriter(output, StandardCharsets.UTF_8);\n\twriter.openJsonObject();\n\twriter.openJsonObjectProperty(\"abc\");\n\twriter.addSimpleJsonObjectPropertyValue(\"1\");\n\twriter.openJsonObjectProperty(\"def\");\n\twriter.addSimpleJsonObjectPropertyValue(2);\n\twriter.openJsonObjectProperty(\"ghi\");\n\twriter.addSimpleJsonObjectPropertyValue(3.00);\n\twriter.closeJsonObject();\n\twriter.close();\n\toutput.close();\n\n\tfinal String result = new String(output.toByteArray(), StandardCharsets.UTF_8);\n\n\treader = new JsonReader(new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8)));\n\tfinal JsonNode nodevalue = reader.read();\n\tSystem.out.println(nodevalue.getJsonDataType() == JsonDataType.OBJECT);\n\t// true\n\tfinal JsonObject jsonObject = (JsonObject) nodevalue;\n\tfor (final Map.Entry\u003cString, Object\u003e jsonObjectProperty : jsonObject) {\n\t\tSystem.out.println(jsonObjectProperty.getKey() + \": \" + jsonObjectProperty.getValue().getClass().getSimpleName() + \": \" + jsonObjectProperty.getValue());\n\t\t// abc: String: 1\n\t\t// def: Integer: 2\n\t\t// ghi: Float: 3.0\n\t}\n} catch (final Exception e) {\n\te.printStackTrace();\n} finally {\n\tUtilities.closeQuietly(output);\n\tUtilities.closeQuietly(writer);\n\tUtilities.closeQuietly(reader);\n}\n```\n\n## JsonArray with JsonWriter and JsonReader example\n```\nJsonWriter writer = null;\nByteArrayOutputStream output = null;\nJsonReader reader = null;\ntry {\n\toutput = new ByteArrayOutputStream();\n\twriter = new JsonWriter(output, StandardCharsets.UTF_8);\n\twriter.openJsonArray();\n\twriter.addSimpleJsonArrayValue(\"1\");\n\twriter.addSimpleJsonArrayValue(2);\n\twriter.addSimpleJsonArrayValue(3.00);\n\twriter.closeJsonArray();\n\twriter.close();\n\toutput.close();\n\n\tfinal String result = new String(output.toByteArray(), StandardCharsets.UTF_8);\n\n\treader = new JsonReader(new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8)));\n\tfinal JsonNode nodevalue = reader.read();\n\tSystem.out.println(nodevalue.getJsonDataType() == JsonDataType.ARRAY);\n\t// true\n\tfinal JsonArray jsonArray = (JsonArray) nodevalue;\n\tfor (final Object jsonArrayItem : jsonArray) {\n\t\tSystem.out.println(jsonArrayItem.getClass().getSimpleName() + \": \" + jsonArrayItem);\n\t\t// String: 1\n\t\t// Integer: 2\n\t\t// Float: 3.0\n\t}\n} catch (final Exception e) {\n\te.printStackTrace();\n} finally {\n\tUtilities.closeQuietly(output);\n\tUtilities.closeQuietly(writer);\n\tUtilities.closeQuietly(reader);\n}\n```\n\n## Sequential read of JSON data objects\n```\nJsonReader jsonReader = null;\ntry {\n\tfinal String data = \"\"\n\t\t\t+ \"{\"\n\t\t\t+ \"\t\\\"level1\\\":\"\n\t\t\t+ \"\t\t[\"\n\t\t\t+ \"\t\t\t{\"\n\t\t\t+ \"\t\t\t\t\\\"property1\\\": \\\"value11\\\",\"\n\t\t\t+ \"\t\t\t\t\\\"property2\\\": \\\"value12\\\",\"\n\t\t\t+ \"\t\t\t\t\\\"property3\\\": \\\"value13\\\"\"\n\t\t\t+ \"\t\t\t},\"\n\t\t\t+ \"\t\t\t{\"\n\t\t\t+ \"\t\t\t\t\\\"property1\\\": \\\"value21\\\",\"\n\t\t\t+ \"\t\t\t\t\\\"property2\\\": \\\"value22\\\",\"\n\t\t\t+ \"\t\t\t\t\\\"property3\\\": \\\"value23\\\"\"\n\t\t\t+ \"\t\t\t}\"\n\t\t\t+ \"\t\t]\"\n\t\t\t+ \"}\";\n\tjsonReader = new JsonReader(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)));\n\tjsonReader.readUpToJsonPath(\"$.level1\");\n\tjsonReader.readNextToken();\n\n\tJsonNode nextJsonNode;\n\tint count = 0;\n\twhile ((nextJsonNode = jsonReader.readNextJsonNode()) != null) {\n\t\tcount++;\n\t\tfinal String property1 = (String) ((JsonObject) nextJsonNode).getSimpleValue(\"property1\");\n\t\tfinal String property2 = (String) ((JsonObject) nextJsonNode).getSimpleValue(\"property2\");\n\t\tfinal String property3 = (String) ((JsonObject) nextJsonNode).getSimpleValue(\"property3\");\n\t\tAssert.assertEquals((\"value\" + count + \"1\"), (property1));\n\t\tAssert.assertEquals((\"value\" + count + \"2\"), (property2));\n\t\tAssert.assertEquals((\"value\" + count + \"3\"), (property3));\n\t}\n} catch (final Exception e) {\n\te.printStackTrace();\n\tAssert.fail(e.getMessage());\n} finally {\n\tUtilities.closeQuietly(jsonReader);\n}\n```\n\n## YamlMapping with YamlWriter and YamlReader example\n```\nJsonWriter writer = null;\nByteArrayOutputStream output = null;\nJsonReader reader = null;\ntry {\n\toutput = new ByteArrayOutputStream();\n\twriter = new JsonWriter(output, StandardCharsets.UTF_8);\n\twriter.openJsonObject();\n\twriter.openJsonObjectProperty(\"abc\");\n\twriter.addSimpleJsonObjectPropertyValue(\"1\");\n\twriter.openJsonObjectProperty(\"def\");\n\twriter.addSimpleJsonObjectPropertyValue(2);\n\twriter.openJsonObjectProperty(\"ghi\");\n\twriter.addSimpleJsonObjectPropertyValue(3.00);\n\twriter.closeJsonObject();\n\twriter.close();\n\toutput.close();\n\n\tfinal String result = new String(output.toByteArray(), StandardCharsets.UTF_8);\n\n\treader = new JsonReader(new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8)));\n\tfinal JsonNode nodevalue = reader.read();\n\tSystem.out.println(nodevalue.getJsonDataType() == JsonDataType.OBJECT);\n\t// true\n\tfinal JsonObject jsonObject = (JsonObject) nodevalue;\n\tfor (final Map.Entry\u003cString, Object\u003e jsonObjectProperty : jsonObject) {\n\t\tSystem.out.println(jsonObjectProperty.getKey() + \": \" + jsonObjectProperty.getValue().getClass().getSimpleName() + \": \" + jsonObjectProperty.getValue());\n\t\t// abc: String: 1\n\t\t// def: Integer: 2\n\t\t// ghi: Float: 3.0\n\t}\n} catch (final Exception e) {\n\te.printStackTrace();\n} finally {\n\tUtilities.closeQuietly(output);\n\tUtilities.closeQuietly(writer);\n\tUtilities.closeQuietly(reader);\n}\n```\n\n## YamlSequence with YamlWriter and YamlReader example\n```\nYamlWriter writer = null;\nByteArrayOutputStream output = null;\nYamlReader reader = null;\ntry {\n\toutput = new ByteArrayOutputStream();\n\twriter = new YamlWriter(output, StandardCharsets.UTF_8);\n\n\tfinal YamlMapping outputSequence = new YamlMapping();\n\toutputSequence.put(\"abc\", \"1\");\n\toutputSequence.put(\"def\", 2);\n\toutputSequence.put(\"ghi\", 3.00);\n\tfinal YamlDocument outputDocument = new YamlDocument().setRoot(outputSequence);\n\twriter.writeDocument(outputDocument);\n\n\tfinal String result = new String(output.toByteArray(), StandardCharsets.UTF_8);\n\n\treader = new YamlReader(new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8)));\n\tfinal YamlDocument document = reader.readDocument();\n\tSystem.out.println(document.getRoot() instanceof YamlMapping);\n\t// true\n\tfinal YamlMapping yamlMapping = (YamlMapping) document.getRoot();\n\tfor (final Map.Entry\u003cString, Object\u003e yamlObjectProperty : yamlMapping) {\n\t\tSystem.out.println(yamlObjectProperty.getKey() + \": \" + yamlObjectProperty.getValue().getClass().getSimpleName() + \": \" + yamlObjectProperty.getValue());\n\t\t// String: 1\n\t\t// Integer: 2\n\t\t// Float: 3.0\n\t}\n} catch (final Exception e) {\n\te.printStackTrace();\n} finally {\n\tUtilities.closeQuietly(output);\n\tUtilities.closeQuietly(writer);\n\tUtilities.closeQuietly(reader);\n}\n```\n\n## Sequential read of YAML data objects\n```\nfinal String testData = \"\"\n\t+ \"level1:\\n\"\n\t+ \"  items:\\n\"\n\t+ \"    - property1: \\\"property 01\\\"\\n\"\n\t+ \"      property2: \\\"property 02\\\"\\n\"\n\t+ \"      property3: \\\"property 03\\\"\\n\"\n\t+ \"    - property1: \\\"property 11\\\"\\n\"\n\t+ \"      property2: \\\"property 12\\\"\\n\"\n\t+ \"      property3: \\\"property 13\\\"\\n\";\n\ntry (InputStream testDataStream = new ByteArrayInputStream(testData.getBytes(StandardCharsets.UTF_8))) {\n\ttry (final YamlReader yamlReader = new YamlReader(testDataStream)) {\n\t\tyamlReader.readUpToPath(\"$.level1.items\");\n\t\tYamlNode nextYamlNode;\n\t\tint count = 0;\n\t\twhile ((nextYamlNode = yamlReader.readNextYamlNode()) != null) {\n\t\t\tfinal String property1 = (String) ((YamlScalar) ((YamlMapping) nextYamlNode).get(\"property1\")).getValue();\n\t\t\tfinal String property2 = (String) ((YamlScalar) ((YamlMapping) nextYamlNode).get(\"property2\")).getValue();\n\t\t\tfinal String property3 = (String) ((YamlScalar) ((YamlMapping) nextYamlNode).get(\"property3\")).getValue();\n\t\t\tAssert.assertTrue((\"property \" + count + \"1\").equals(property1));\n\t\t\tAssert.assertTrue((\"property \" + count + \"2\").equals(property2));\n\t\t\tAssert.assertTrue((\"property \" + count + \"3\").equals(property3));\n\t\t\tcount++;\n\t\t}\n\t}\n} catch (final Exception e) {\n\te.printStackTrace();\n}\n```\n\nFor other simple examples see test class \"de.soderer.json.JsonTest\" and class \"de.soderer.yaml.YamlTest\":\n\nhttps://github.com/hudeany/json/blob/master/src/test/java/de/soderer/json/JsonTest.java\n  \n## Maven2 repository\nThis library is also available via Maven2 repository\n\n```\n\u003crepositories\u003e\n\t\u003crepository\u003e\n\t\t\u003cid\u003ede.soderer\u003c/id\u003e\n\t\t\u003curl\u003ehttps://soderer.de/maven2\u003c/url\u003e\n\t\u003c/repository\u003e\n\u003c/repositories\u003e\n\n\u003cdependency\u003e\n\t\u003cgroupId\u003ede.soderer\u003c/groupId\u003e\n\t\u003cartifactId\u003ejson\u003c/artifactId\u003e\n\t\u003cversion\u003eRELEASE\u003c/version\u003e\n\u003c/dependency\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhudeany%2Fjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhudeany%2Fjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhudeany%2Fjson/lists"}