https://github.com/lightweight-component/aj-json
Small JSON parser & serializer
https://github.com/lightweight-component/aj-json
java-json json
Last synced: 29 days ago
JSON representation
Small JSON parser & serializer
- Host: GitHub
- URL: https://github.com/lightweight-component/aj-json
- Owner: lightweight-component
- License: apache-2.0
- Created: 2025-06-17T07:20:13.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-06-17T07:31:48.000Z (9 months ago)
- Last Synced: 2025-08-20T21:54:41.154Z (7 months ago)
- Topics: java-json, json
- Language: Java
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://central.sonatype.com/artifact/com.ajaxjs/aj-json)
[](https://javadoc.io/doc/com.ajaxjs/aj-json)
[](https://deepwiki.com/lightweight-component/aj-json)
[](http://www.apache.org/licenses/LICENSE-2.0.txt)
[](mailto:frank@ajaxjs.com)
# Small JSON parser & serializer 小型 JSON 解释器
小型 JSON 解析器,实现 JSON 与 Map/List 互换,是了解 JSON 解析的好例子。
This is a lightweight JSON parser that implements bidirectional conversion between JSON strings and Java data structures such as Map and List.
The implementation is simple yet powerful, making it an excellent example for learning how JSON parsing works under the hood.
## Source code
[Github](https://github.com/lightweight-component/aj-json) | [Gitcode](https://gitcode.com/lightweight-component/aj-json)
# Install
Requires Java 1.8+, Maven Snippets:
```xml
com.ajaxjs
aj-json
1.4
```
# Usage
```java
// Java to JSON
Object obj = true;
String json = ConvertToJson.toJson(obj);
assertEquals("true", json);
obj = 123;
json = ConvertToJson.toJson(obj);
assertEquals("123", json);
obj = 100000000000000001L;
json = ConvertToJson.toJson(obj);
assertEquals("\"100000000000000001\"", json);
obj = 99999L;
json = ConvertToJson.toJson(obj);
assertEquals("99999", json);
obj = "hello";
json = ConvertToJson.toJson(obj);
assertEquals("\"hello\"", json);
Map map = new HashMap();
map.put("name", "John");
map.put("age", 30);
json = ConvertToJson.toJson(map);
assertEquals("{\"name\":\"John\",\"age\":30}", json);
// List to JSON
List list = new ArrayList();
list.add(1);
list.add(2);
list.add(3);
String json = ConvertToJson.list2Json(list);
assertEquals("[1, 2, 3]", json);
```