Package net.sourceforge.plantuml.json
Class Json
java.lang.Object
net.sourceforge.plantuml.json.Json
This class serves as the entry point to the minimal-json API.
To parse a given JSON input, use the parse()
methods like in this example:
JsonObject object = Json.parse(string).asObject();
To create a JSON data structure to be serialized, use the
methods value(), array(), and
object(). For example, the following snippet will produce the
JSON string {"foo": 23, "bar": true}:
String string = Json.object().add("foo", 23).add("bar", true).toString();
To create a JSON array from a given Java array, you can use one of the
array() methods with varargs parameters:
String[] names = ... JsonArray array = Json.array(names);
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonArrayarray()Creates a new empty JsonArray.static JsonArrayarray(boolean... values) Creates a new JsonArray that contains the JSON representations of the givenbooleanvalues.static JsonArrayarray(double... values) Creates a new JsonArray that contains the JSON representations of the givendoublevalues.static JsonArrayarray(float... values) Creates a new JsonArray that contains the JSON representations of the givenfloatvalues.static JsonArrayarray(int... values) Creates a new JsonArray that contains the JSON representations of the givenintvalues.static JsonArrayarray(long... values) Creates a new JsonArray that contains the JSON representations of the givenlongvalues.static JsonArrayCreates a new JsonArray that contains the JSON representations of the given strings.static JsonObjectobject()Creates a new empty JsonObject.static JsonValueReads the entire input from the given reader and parses it as JSON.static JsonValueParses the given input string as JSON.static JsonValuevalue(boolean value) Returns a JsonValue instance that represents the givenbooleanvalue.static JsonValuevalue(double value) Returns a JsonValue instance that represents the givendoublevalue.static JsonValuevalue(float value) Returns a JsonValue instance that represents the givenfloatvalue.static JsonValuevalue(int value) Returns a JsonValue instance that represents the givenintvalue.static JsonValuevalue(long value) Returns a JsonValue instance that represents the givenlongvalue.static JsonValueReturns a JsonValue instance that represents the given string.
-
Field Details
-
NULL
Represents the JSON literalnull. -
TRUE
Represents the JSON literaltrue. -
FALSE
Represents the JSON literalfalse.
-
-
Method Details
-
value
Returns a JsonValue instance that represents the givenintvalue.- Parameters:
value- the value to get a JSON representation for- Returns:
- a JSON value that represents the given value
-
value
Returns a JsonValue instance that represents the givenlongvalue.- Parameters:
value- the value to get a JSON representation for- Returns:
- a JSON value that represents the given value
-
value
Returns a JsonValue instance that represents the givenfloatvalue.- Parameters:
value- the value to get a JSON representation for- Returns:
- a JSON value that represents the given value
-
value
Returns a JsonValue instance that represents the givendoublevalue.- Parameters:
value- the value to get a JSON representation for- Returns:
- a JSON value that represents the given value
-
value
Returns a JsonValue instance that represents the given string.- Parameters:
string- the string to get a JSON representation for- Returns:
- a JSON value that represents the given string
-
value
Returns a JsonValue instance that represents the givenbooleanvalue.- Parameters:
value- the value to get a JSON representation for- Returns:
- a JSON value that represents the given value
-
array
Creates a new empty JsonArray. This is equivalent to creating a new JsonArray using the constructor.- Returns:
- a new empty JSON array
-
array
Creates a new JsonArray that contains the JSON representations of the givenintvalues.- Parameters:
values- the values to be included in the new JSON array- Returns:
- a new JSON array that contains the given values
-
array
Creates a new JsonArray that contains the JSON representations of the givenlongvalues.- Parameters:
values- the values to be included in the new JSON array- Returns:
- a new JSON array that contains the given values
-
array
Creates a new JsonArray that contains the JSON representations of the givenfloatvalues.- Parameters:
values- the values to be included in the new JSON array- Returns:
- a new JSON array that contains the given values
-
array
Creates a new JsonArray that contains the JSON representations of the givendoublevalues.- Parameters:
values- the values to be included in the new JSON array- Returns:
- a new JSON array that contains the given values
-
array
Creates a new JsonArray that contains the JSON representations of the givenbooleanvalues.- Parameters:
values- the values to be included in the new JSON array- Returns:
- a new JSON array that contains the given values
-
array
Creates a new JsonArray that contains the JSON representations of the given strings.- Parameters:
strings- the strings to be included in the new JSON array- Returns:
- a new JSON array that contains the given strings
-
object
Creates a new empty JsonObject. This is equivalent to creating a new JsonObject using the constructor.- Returns:
- a new empty JSON object
-
parse
Parses the given input string as JSON. The input must contain a valid JSON value, optionally padded with whitespace.- Parameters:
string- the input string, must be valid JSON- Returns:
- a value that represents the parsed JSON
- Throws:
ParseException- if the input is not valid JSON
-
parse
Reads the entire input from the given reader and parses it as JSON. The input must contain a valid JSON value, optionally padded with whitespace.Characters are read in chunks into an input buffer. Hence, wrapping a reader in an additional
BufferedReaderlikely won't improve reading performance.- Parameters:
reader- the reader to read the JSON value from- Returns:
- a value that represents the parsed JSON
- Throws:
IOException- if an I/O error occurs in the readerParseException- if the input is not valid JSON
-