$ show stleary/JSON-java
The JSON-java library is a reference implementation for JSON processing in Java. It provides core functionality for parsing JSON strings into Java objects (JSONObject and JSONArray) and generating JSON from Java objects. Additionally, it includes conversion utilities for transforming JSON to/from XML, HTTP headers, cookies, comma-delimited lists (CDL), and properties files. The library is designed to be dependency-free, backward compatible (supporting Java 1.6 to 25), and adheres strictly to JSON specifications. Its architecture is modular, with separate classes handling parsing (JSONTokener), generation (JSONStringer, JSONWriter), and format conversions (XML, Cookie, etc.), all coordinated through configuration classes that use a fluent builder pattern.
The LLM identified 3 files worth highlighting for reuse:
Implements a fluent configuration pattern for controlling XML-to-JSON conversion behavior. Features predefined constants (ORIGINAL, KEEP_STRINGS) and composable settings via with*() methods. Demonstrates clean separation of configuration concerns, allowing users to fine-tune parsing behavior (e.g., preserving strings, handling nil attributes) without telescoping constructors. Highly reusable as a configuration template for other parsers or builders.
A low-level JSON tokenizer that breaks input into parseable tokens. Used internally by JSONObject and JSONArray but can be extracted for custom JSON processing tasks. Demonstrates strong encapsulation of tokenization logic with minimal dependencies (primarily JSONException and configuration classes). Exhibits non-obvious skill in handling JSON syntax edge cases (comments, unquoted keys in lenient mode) while maintaining a simple, reusable API for token-by-token parsing.
Provides a fluent API for incrementally building JSON text. Dependencies are limited to JSONException and a Writer (e.g., StringWriter). Demonstrates the builder pattern applied to JSON generation, allowing efficient construction of complex JSON structures without intermediate object creation. The clean, chainable interface (e.g., stringer.object().key('value').value(42).endObject()) is easily reusable in any project requiring programmatic JSON assembly.