{"id":24901757,"url":"https://github.com/antonsjava/json","last_synced_at":"2026-02-11T22:51:15.217Z","repository":{"id":57732436,"uuid":"145204617","full_name":"antonsjava/json","owner":"antonsjava","description":" json - small library for manipulating json data structures","archived":false,"fork":false,"pushed_at":"2025-02-24T11:38:06.000Z","size":123,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T18:19:50.734Z","etag":null,"topics":["java","json"],"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/antonsjava.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":"2018-08-18T08:47:08.000Z","updated_at":"2025-02-24T11:38:10.000Z","dependencies_parsed_at":"2025-02-24T12:28:42.116Z","dependency_job_id":"f586b942-0fe0-494d-a041-3174b7281ba9","html_url":"https://github.com/antonsjava/json","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonsjava%2Fjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonsjava%2Fjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonsjava%2Fjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonsjava%2Fjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonsjava","download_url":"https://codeload.github.com/antonsjava/json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248819977,"owners_count":21166576,"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","json"],"created_at":"2025-02-01T21:17:38.611Z","updated_at":"2026-02-11T22:51:10.174Z","avatar_url":"https://github.com/antonsjava.png","language":"Java","readme":"\n# json\n\njson is small library for manipulating json data structures.It is useful, \nwhen you need to create small json data directly (without java binding).\n\nIt is possible to parse json string info java tree like data structure and\nbuild java tree like data structure and convert them into json string. \n\n\n## Data structures\n\nAll provided data structures are defined by set of interfaces. Library provides \nimplementation for all of those interfaces. Most of them can be instantiated using \nfactory class JsonFactory. \n\n### JsonValue\n\nGeneric json value. It is abstract representation of one of JsonObject, JsonArray \nor one onf JsonLiteral instance. It is not possible to instantiate this type of object.\n\n### JsonObject\n\njson object representation with set of named attrinutes. (JsonFactory.object())\n\n### JsonArray\n\njson array representation with set of json values. (JsonFactory.array())\n.\n### JsonLiteral\n\nGeneric json literal value. There are set of subclasses of this class. \n - JsonBoolLiteral - boolean json literal (true, false) (JsonFactory.boolLiteral())\n - JsonExpLiteral - exponential json literal (12E-1, -2E12, ...) (JsonFactory.expLiteral())\n - JsonFracLiteral - fraction json literal (12.3, -33.23, ...) (JsonFactory.fracLiteral())\n - JsonIntLiteral - int json literal (1, 2212342, ...) (JsonFactory.intLiteral())\n - JsonNullLiteral - null json literal (null) (JsonFactory.nullLiteral())\n - JsonStringLiteral - string json literal (\"foo\", \"bar\", ...) (JsonFactory.stringLiteral())\n\n## Json parsing to tree \n\nYou can parse json strings easily by calling \n```java\n  String jsonvalue = .....\n  JsonValue value = JsonParser.parse(jsonvalue);\n```\nor \n```java\n  Reader jsonvalue = .....\n  JsonValue value = JsonParser.parse(jsonvalue);\n```\n\n## Json parsing to stream \n\n  You can traverse json tree and produces stream of json values \n  \n  Useful, when you have big json and you want to extract only small \n  json sub tree at once.\n \n  Imagine you have json like \n```\n  { \"items\" : [\n \t\t{\"name\": \"name-1\", \"value\": 1},\n \t\t{\"name\": \"name-2\", \"value\": 2},\n \t\t{\"name\": \"name-3\", \"value\": 3},\n \t\t{\"name\": \"name-4\", \"value\": 4},\n \t\t...\n  ]\n  }\n```\n  So you can parse whole json and iterate parts. In this case whole \n  json is loaded before traversal. (It is effective for small jsons \n  only)\n```java\n    JsonValue root = JsonParser.parse(inputstream);\n    root.find(SPM.path(\"items\", \"*\")).stream()\n    // or if you want traverse only values\n    // root.find(SPM.path(\"items\", \"*\", \"value\")).stream()\n```\n  This class allows you to read only parts you want. But it is little \n  bit slower.\n```java\n    JsonStream.instance(inputstream, SPM.path(\"items\", \"*\")).stream();\n    // or if you want traverse only values\n    // JsonStream.instance(inputstream, SPM.path(\"items\", \"*\", \"value\")).stream();\n```\n  So if you have pretty big json which is json array and you are goinig to \n  process it item by item, you can use JsonStream with path \"*\".  \n\n\n## Json to string conversion\n\nTo obtain string representation of json data structure you can call \n```java\n  JsonValue jsonvalue = .....\n  String onelinestring = jsonvalue.toCompactString();\n  String indendedstirng = jsonvalue.toPrettyString(\"\\t\");\n```\n\n## Building json structure\n\nTo create simple instances of json data structures you can use JsonFactory class.\nThan it is possible to use appropriate API from JsonObject or JsonArray to build \nwhole json data structure tree. \n\n\nThis is simple example of such construction of following data structure\n\n```json\n{\n  \"name\" : \"John\",\n  \"surname\" : \"Smith\",\n  \"titles\" : [\n    \"Mudr.\",\n    \"Phd.\"\n  ]\n}\n```\n\n```java\n  JsonObject person = JsonFactory.object()\n    .add(\"name\", JsonFactory.stringLiteral(\"John\"))\n    .add(\"surname\", JsonFactory.stringLiteral(\"Smith\"))\n    .add(\"titles\", JsonFactory.array()\n        .add(JsonFactory.stringLiteral(\"Mudr.\"))\n        .add(JsonFactory.stringLiteral(\"Phd.\"))\n      );\n```\n\n## Searching json structure\n\nIf you have json structure and you can identify some substructure by \npath, you can find them by calling  \n\n```java\n  JsonObject o = ...\n  JsonValue v = o.find(\"menu\", \"popup\", \"menuitem\", \"*\", \"value\").first();\n  JsonValue v = o.findFirst(SimplePathMatcher.instance(\"menu\", \"popup\", \"menuitem\", \"*\", \"value\"));\n  List\u003cJsonValue\u003e list = o.find(\"menu\", \"popup\", \"menuitem\", \"*\", \"value\").all();\n  List\u003cJsonValue\u003e list = o.findAll(SimplePathMatcher.instance(\"menu\", \"popup\", \"menuitem\", \"*\", \"value\"));\n```\n\nCharacter '\\*' stands for any path item. \n\nIf you search for literal values you can call \n\n```java\n  JsonObject o = ...\n  Stirng v = o.find(\"menu\", \"popup\", \"menuitem\", \"*\", \"value\").findLiteral();\n  Stirng v = o.findFirstLiteral(SimplePathMatcher.instance(\"menu\", \"popup\", \"menuitem\", \"*\", \"value\"));\n  List\u003cString\u003e list = o.find(\"menu\", \"popup\", \"menuitem\", \"*\", \"value\").allLiterals();\n  List\u003cString\u003e list = o.findAllLiterals(SimplePathMatcher.instance(\"menu\", \"popup\", \"menuitem\", \"*\", \"value\"));\n```\n\nIf you search for literal from big structure and you don;t want to parse if first.\nvalues you can call following code. But it is faster only for special cases \n\n```java\n  String value = LiteralParser.firstAsString(\n                    StringSource.instance(json)\n                    , SimplePathMatcher.instance(\"*\", \"cars\", \"*\"));\n```\n\n## Wild Searching json structure\n\nIt is possible to use WildPathMatcher for searching. In this case there are two types of path \nelements. \n - single wild path element - it is direct name or you van use * and ? to represent more/single\n   characters in single path element. (like \"car-*\" or \"car-??\")\n - multiple wild path element \"**\" - it represents any sequence of path elements. \nJsonObject\nExample:\n```java\n  List\u003cString\u003e list = o.findAllLiterals(WPM.fromPath(\"**/person-*/surname\"));\n```\n\n\n\n## Formatting without complete parsing\n\nIf you have a json structure and you want to transform it to noindent form or to \nindent form and you don't want to parse it You can use simplified formatting.\nIt works for well formated json structures only. \n\nThe class don't make full parsing of input. Implementation just tries to recognize \nblank characters and string literals and transform them somehow.\n\n```java\n  String json = ...\n  String formatedJson = JsonFormat.from(json).indent(2, ' ').toText();\n  String formatedJson = JsonFormat.from(json).noindent().toText();\n```\nOr you can use Reader/Writer version\n\n```java\n  Reader jsonReader = ...\n  Writer jsonWriter = ...\n  JsonFormat.from(jsonReader).indent(\"  \").toWriter(jsonWriter);\n  JsonFormat.from(jsonReader).noindent().toWriter(jsonWriter);\n```\nThere is also possible to cut string literals to defined length. This can be useful\nfor logging json which contains very long data (like binaries), which are not necessary \nto log fully.\n\n```java\n  String json = ...\n  String formatedJson = JsonFormat.from(json).indent(\"  \").cutStringLiterals(50).toText();\n```\n\nThe result can looks like \n\n```json\n{\n  \"name\" : \"image.jpg\",\n  \"bytes\" : \"VGhlcmUgaXMgYWxzbyBwb3NzaWJsZSB0byBjdXQgc3RyaW5nIGxpdG ...\"\n}\n```\n\n\n\n## Maven usage\n\n```\n   \u003cdependency\u003e\n      \u003cgroupId\u003eio.github.antonsjava\u003c/groupId\u003e\n      \u003cartifactId\u003ejson\u003c/artifactId\u003e\n      \u003cversion\u003eLATESTVERSION\u003c/version\u003e\n   \u003c/dependency\u003e\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonsjava%2Fjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonsjava%2Fjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonsjava%2Fjson/lists"}