Interface JSONValue
- All Superinterfaces:
Formattable
- All Known Subinterfaces:
JSONArray, JSONNumber, JSONObject, JSONString
- All Known Implementing Classes:
JSONArrayImpl, JSONLiteral, JSONNumberImpl, JSONObjectImpl, JSONStringImpl
This interface describes the base for all the JSON datatypes.
JSONValue implements
Formattable
for the implementation of pretty-printed output through
String.format( "%s", value ) or similar.
formatTo(Formatter,int,int,int)
ignores the arguments flags and precision, while the
width argument is used internally. Therefore, a call like
String.format( "%10s", value ) may result in some unexpected
output.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: JSONValue.java 1258 2026-06-04 18:33:06Z tquadrat $
- Since:
- 0.25.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.jsonbuilder.JSONValue"
-
Method Summary
Modifier and TypeMethodDescriptiondefault JSONArrayasArray()Returns this JSON value asJSONArray, assuming that this value represents a JSON array.default JSONLiteralReturns this JSON value as JSON literalsfalseortrue, assuming that this value represents a JSON Boolean.default JSONNumberasNumber()Returns this JSON value asJSONNumber, assuming that this value represents a JSON number.default JSONObjectasObject()Returns this JSON value asJSONObject, assuming that this value represents a JSON object.default JSONStringasString()Returns this JSON value asJSONString, assuming that this value represents a JSON String.voiddefault booleanisArray()Detects whether this value represents a JSON array.default booleanDetects whether this value represents a boolean value.default booleanisFalse()Detects whether this value represents the JSON literalfalse.default booleanisNull()Detects whether this value represents the JSON literalnull.default booleanisNumber()Detects whether this value represents a JSON number.default booleanisObject()Detects whether this value represents a JSON object.default booleanisString()Detects whether this value represents a JSON string.default booleanisTrue()Detects whether this value represents the JSON literaltrue.toString()
-
Method Details
-
asArray
Returns this JSON value as
JSONArray, assuming that this value represents a JSON array. If this is not the case, anIllegalStateExceptionis thrown.- Returns:
- This
JSONValueinstance as aJSONArray. - Throws:
IllegalStateException- This JSON value is not a JSON array.
-
asBoolean
Returns this JSON value as JSON literals
falseortrue, assuming that this value represents a JSON Boolean. If this is not the case, anIllegalStateExceptionis thrown.- Returns:
- This
JSONValueinstance as aJSONLiteral. - Throws:
IllegalStateException- This JSON value is not a JSON Boolean.
-
asNumber
Returns this JSON value as
JSONNumber, assuming that this value represents a JSON number. If this is not the case, anIllegalStateExceptionis thrown.- Returns:
- This
JSONValueinstance as aJSONNumber. - Throws:
IllegalStateException- This JSON value is not a JSON String.
-
asObject
Returns this JSON value as
JSONObject, assuming that this value represents a JSON object. If this is not the case, anIllegalStateExceptionis thrown.- Returns:
- This
JSONValueinstance as aJSONObject. - Throws:
IllegalStateException- This JSON value is not a JSON object.
-
asString
Returns this JSON value as
JSONString, assuming that this value represents a JSON String. If this is not the case, anIllegalStateExceptionis thrown.- Returns:
- This
JSONValueinstance as aJSONString. - Throws:
IllegalStateException- This JSON value is not a JSON String.
-
formatTo
- Specified by:
formatToin interfaceFormattable
-
isBoolean
Detects whether this value represents a boolean value.
- Returns:
trueif this value represents either the JSON literaltrueorJSONLiteral.FALSE.
-
isArray
-
isFalse
Detects whether this value represents the JSON literal
false.- Returns:
trueif this value represents the JSON literalfalse.
-
isNull
Detects whether this value represents the JSON literal
null.- Returns:
trueif this value represents the JSON literalnull.
-
isNumber
Detects whether this value represents a JSON number. If this is the case, this value is an instance of
JSONNumber.- Returns:
trueif this value is an instance ofJSONObject,falseotherwise.
-
isObject
Detects whether this value represents a JSON object. If this is the case, this value is an instance of
JSONObject.- Returns:
trueif this value is an instance ofJSONObject,falseotherwise.
-
isString
Detects whether this value represents a JSON string. If this is the case, this value is an instance of
JSONString.- Returns:
trueif this value is an instance ofJSONString,falseotherwise.
-
isTrue
Detects whether this value represents the JSON literal
true.- Returns:
trueif this value represents the JSON literaltrue.
-
toString
-
