RFC8259 describes the JSON data model and interchange format, which is widely used in application-level protocols including RESTful APIs. It is common for applications to request resources via the HTTP POST method, with JSON entities. However, POST is suboptimal for requests which do not modify a resource's state. JSON→URL defines a text format for the JSON data model suitable for use within a URL/URI.
The factory artifact defines a generic JSON->URL parser and includes an implementation based Java SE data types (e.g. java.util.Map, java.util.List, etc). There are two additional modules, distributed as separate artifacts, which implement a parser based on JSR-374 and Douglas Crockford's Java API.
Java SE API example:
<dependencies>
<dependency>
<groupId>org.jsonurl</groupId>
<artifactId>jsonurl-factory</artifactId>
<version>${jsonurl.version}</version>
</dependency>
</dependencies>
import java.util.Map;
import org.jsonurl.j2se.JsonUrlParser;
JsonUrlParser p = new JsonUrlParser();
Map obj = p.parseObject( "(Hello:World!)" );
System.out.println(obj.get("Hello")) // World!
Json.org example:
<dependencies>
<dependency>
<groupId>org.jsonurl</groupId>
<artifactId>jsonurl-jsonorg</artifactId>
<version>${jsonurl.version}</version>
</dependency>
</dependencies>
import org.json.JSONObject;
import org.jsonurl.jsonorg.JsonUrlParser;
JsonUrlParser p = new JsonUrlParser();
JSONObject obj = p.parseObject( "(Hello:World!)" );
System.out.println(obj.get("Hello")) // World!
JSR-374 example:
<dependencies>
<dependency>
<groupId>org.jsonurl</groupId>
<artifactId>jsonurl-jsr374</artifactId>
<version>${jsonurl.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>${javax.json.version}</version>
</dependency>
</dependencies>
import javax.json.JsonObject;
import org.jsonurl.jsonp.JsonUrlParser;
JsonUrlParser p = new JsonUrlParser();
JsonObject obj = p.parseObject( "(Hello:World!)" );
System.out.println(obj.get("Hello")) // World!
All artifacts published to Maven Central include sources
and javadoc
JARs.
You can browse the current, and all previous revisions, via Javadoc.io:
Additionally, Javadocs are also generated automatically on pushes to main.
The parser is designed to parse untrusted input. It supports limits on the number of parsed values and depth of nested arrays or objects. When the limit is exceeded a LimitException is thrown. Sane limit values are set by default.