Fast JSON

A fast JSON library written in Java

License

License

Categories

Categories

JSON Data
GroupId

GroupId

me.joshlarson
ArtifactId

ArtifactId

fast-json
Last Version

Last Version

3.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Fast JSON
A fast JSON library written in Java
Project URL

Project URL

https://github.com/Josh-Larson/fast-json
Source Code Management

Source Code Management

https://github.com/Josh-Larson/fast-json

Download fast-json

How to add to project

<!-- https://jarcasting.com/artifacts/me.joshlarson/fast-json/ -->
<dependency>
    <groupId>me.joshlarson</groupId>
    <artifactId>fast-json</artifactId>
    <version>3.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/me.joshlarson/fast-json/
implementation 'me.joshlarson:fast-json:3.0.1'
// https://jarcasting.com/artifacts/me.joshlarson/fast-json/
implementation ("me.joshlarson:fast-json:3.0.1")
'me.joshlarson:fast-json:jar:3.0.1'
<dependency org="me.joshlarson" name="fast-json" rev="3.0.1">
  <artifact name="fast-json" type="jar" />
</dependency>
@Grapes(
@Grab(group='me.joshlarson', module='fast-json', version='3.0.1')
)
libraryDependencies += "me.joshlarson" % "fast-json" % "3.0.1"
[me.joshlarson/fast-json "3.0.1"]

Dependencies

runtime (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

How to use it:

Download

Read:

To read, there are several options. First is using the convenience class JSON:

String json = "...";
JSONObject obj = JSON.readObject(json, true); // Second argument is whether or not to print errors

Second is using a string:

String json = "...";
JSONObject obj;
try (JSONInputStream in = new JSONInputStream(json)) {
	obj = in.readObject();
} catch (IOException | JSONException e) {
	e.printStackTrace();
}

Third is using an input stream, such as a file:

JSONObject obj;
try (JSONInputStream in = new JSONInputStream(new FileInputStream(new File("myjson.txt")))) {
	obj = in.readObject();
} catch (IOException | JSONException e) {
	e.printStackTrace();
}

Write:

For write, there are two options. First is using the toString() function:

JSONObject obj = new JSONObject();
obj.put("myint", 5);
System.out.println(obj.toString());

Behind the scenes, it creates a new byte array output stream and uses the following method to create the string. Second option is using an output stream:

JSONObject obj = new JSONObject();
obj.put("myint", 5);
try (JSONOutputStream out = new JSONOutputStream(new FileOutputStream(new File("myjson.txt")))) {
	out.writeObject(obj);
} catch (IOException e) {
	e.printStackTrace();
}

Additional Note(s):

  • There is both a JSONObject and an JSONArray, both are compatible with the input and output streams.
  • The class JSON will automatically clean up stream resources

Versions

Version
3.0.1
1.7