Object JSON
-
- All Implemented Interfaces:
public class JSONJSON core library - a set of functions to assist with the creation and output of JSON data.
-
-
Field Summary
Fields Modifier and Type Field Description private IntegerdefaultOutputBuilderSizeprivate final StringasStringprivate final StringasStringOrNullprivate final LongasLongprivate final LongasLongOrNullprivate final IntegerasIntprivate final IntegerasIntOrNullprivate final ShortasShortprivate final ShortasShortOrNullprivate final ByteasByteprivate final ByteasByteOrNullprivate final ULongasULongprivate final ULongasULongOrNullprivate final UIntasUIntprivate final UIntasUIntOrNullprivate final UShortasUShortprivate final UShortasUShortOrNullprivate final UByteasUByteprivate final UByteasUByteOrNullprivate final BigDecimalasDecimalprivate final BigDecimalasDecimalOrNullprivate final BooleanasBooleanprivate final BooleanasBooleanOrNullprivate final JSONArrayasArrayprivate final JSONArrayasArrayOrNullprivate final JSONObjectasObjectprivate final JSONObjectasObjectOrNullpublic final static JSONINSTANCE
-
Method Summary
Modifier and Type Method Description final JSONIntof(Integer value)Create a JSONInt from an Int value. final JSONLongof(Long value)Create a JSONLong from a Long value. final JSONDecimalof(BigDecimal value)Create a JSONDecimal from a BigDecimal value. final JSONStringof(String value)Create a JSONString from a String value. final JSONBooleanof(Boolean value)Create a JSONBoolean from a Boolean value. final JSONArrayof(JSONValue items)Create a JSONArray from a vararglist of JSONValue items.final JSONObjectof(Pair<String, JSONValue> items)Create a JSONArray from a vararglist of Pair of name to value pairs.final JSONValueparse(String json)Parse a String to a JSONValue (or nullif the string is"null").final JSONValueparseNonNull(String json)Parse a String to a JSONValue (guaranteed non-null). final JSONArrayparseArray(String json)Parse a String to a JSONArray. final JSONObjectparseObject(String json)Parse a String to a JSONObject. final JSONArrayparseLines(String jsonLines)Parse a String to a JSONArray, where the input is in JSON Lines form. final StringtoJSON(JSONValue $self)Convert the receiver JSONValue to a JSON string ( "null"if the receiver isnull).final UnitappendTo(JSONValue $self, Appendable a)Append the receiver JSONValue as a JSON string ( "null"if the receiver isnull) to an Appendable.final UnitoutputTo(JSONValue $self, IntConsumer out)Output the receiver JSONValue as a JSON string ( "null"if the receiver isnull) to an IntConsumer (a character at a time).final Unitoutput(JSONValue $self, IntConsumer out)Output the receiver JSONValue as a JSON string ( "null"if the receiver isnull) to an IntConsumer (a character at a time).final UnitcoOutputTo(JSONValue $self, SuspendFunction1<Character, Unit> out)Output the receiver JSONValue as a JSON string ( "null"if the receiver isnull) to a CoOutput (a character at a time).final UnitcoOutput(JSONValue $self, SuspendFunction1<Character, Unit> out)Output the receiver JSONValue as a JSON string ( "null"if the receiver isnull) to a CoOutput (a character at a time).final AppendableappendJSONValue(Appendable $self, JSONValue json)Append a JSONValue as a JSON string ( "null"if the value isnull) to the receiver Appendable.final StringdisplayValue(JSONValue $self, Integer maxString)Convert the receiver JSONValue to a string suitable for use in human-readable messages. final StringelidedValue(JSONValue $self, Collection<String> exclude, Collection<String> include, String substitute)Convert the receiver JSONValue to a string of JSON with nominated values elided (replaced by a substitute string). final StringasStringOr(JSONValue $self, Function1<JSONValue, String> alternative)Get the receiver JSONValue as a String if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final LongasLongOr(JSONValue $self, Function1<JSONValue, Long> alternative)Get the receiver JSONValue as a Long if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final IntegerasIntOr(JSONValue $self, Function1<JSONValue, Integer> alternative)Get the receiver JSONValue as an Int if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final ShortasShortOr(JSONValue $self, Function1<JSONValue, Short> alternative)Get the receiver JSONValue as a Short if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final ByteasByteOr(JSONValue $self, Function1<JSONValue, Byte> alternative)Get the receiver JSONValue as a Byte if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final ULongasULongOr(JSONValue $self, Function1<JSONValue, ULong> alternative)Get the receiver JSONValue as a ULong if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final UIntasUIntOr(JSONValue $self, Function1<JSONValue, UInt> alternative)Get the receiver JSONValue as a UInt if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final UShortasUShortOr(JSONValue $self, Function1<JSONValue, UShort> alternative)Get the receiver JSONValue as a UShort if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final UByteasUByteOr(JSONValue $self, Function1<JSONValue, UByte> alternative)Get the receiver JSONValue as a UByte if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final BigDecimalasDecimalOr(JSONValue $self, Function1<JSONValue, BigDecimal> alternative)Get the receiver JSONValue as a BigDecimal if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final BooleanasBooleanOr(JSONValue $self, Function1<JSONValue, Boolean> alternative)Get the receiver JSONValue as a Boolean if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final JSONArrayasArrayOr(JSONValue $self, Function1<JSONValue, JSONArray> alternative)Get the receiver JSONValue as a JSONArray if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final JSONObjectasObjectOr(JSONValue $self, Function1<JSONValue, JSONObject> alternative)Get the receiver JSONValue as a JSONObject if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception). final StringasStringOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as a String, or throw a JSONTypeException if incorrect. final LongasLongOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as a Long, or throw a JSONTypeException if incorrect. final IntegerasIntOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as an Int, or throw a JSONTypeException if incorrect. final ShortasShortOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as a Short, or throw a JSONTypeException if incorrect. final ByteasByteOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as a Byte, or throw a JSONTypeException if incorrect. final ULongasULongOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as a ULong, or throw a JSONTypeException if incorrect. final UIntasUIntOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as a UInt, or throw a JSONTypeException if incorrect. final UShortasUShortOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as a UShort, or throw a JSONTypeException if incorrect. final UByteasUByteOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as a UByte, or throw a JSONTypeException if incorrect. final BigDecimalasDecimalOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as a BigDecimal, or throw a JSONTypeException if incorrect. final BooleanasBooleanOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as a Boolean, or throw a JSONTypeException if incorrect. final JSONArrayasArrayOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as a JSONArray, or throw a JSONTypeException if incorrect. final JSONObjectasObjectOrError(JSONValue $self, String target, Object key, String nodeName)Get the receiver JSONValue as a JSONObject, or throw a JSONTypeException if incorrect. final VoidtypeError(JSONValue $self, String target, Object key, String nodeName)Throw a JSONTypeException with the given parameters. final Unitaccept(IntConsumer $self, CharSequence cs)Output a CharSequence (e.g. final IntegergetDefaultOutputBuilderSize()The default output buffer size for toJSON()operations (JSONArrayandJSONObject)final UnitsetDefaultOutputBuilderSize(Integer defaultOutputBuilderSize)final StringgetAsString(JSONValue $self)final StringgetAsStringOrNull(JSONValue $self)final LonggetAsLong(JSONValue $self)final LonggetAsLongOrNull(JSONValue $self)final IntegergetAsInt(JSONValue $self)final IntegergetAsIntOrNull(JSONValue $self)final ShortgetAsShort(JSONValue $self)final ShortgetAsShortOrNull(JSONValue $self)final BytegetAsByte(JSONValue $self)final BytegetAsByteOrNull(JSONValue $self)final ULonggetAsULong(JSONValue $self)final ULonggetAsULongOrNull(JSONValue $self)final UIntgetAsUInt(JSONValue $self)final UIntgetAsUIntOrNull(JSONValue $self)final UShortgetAsUShort(JSONValue $self)final UShortgetAsUShortOrNull(JSONValue $self)final UBytegetAsUByte(JSONValue $self)final UBytegetAsUByteOrNull(JSONValue $self)final BigDecimalgetAsDecimal(JSONValue $self)final BigDecimalgetAsDecimalOrNull(JSONValue $self)final BooleangetAsBoolean(JSONValue $self)final BooleangetAsBooleanOrNull(JSONValue $self)final JSONArraygetAsArray(JSONValue $self)final JSONArraygetAsArrayOrNull(JSONValue $self)final JSONObjectgetAsObject(JSONValue $self)final JSONObjectgetAsObjectOrNull(JSONValue $self)-
-
Method Detail
-
of
final JSONDecimal of(BigDecimal value)
Create a JSONDecimal from a BigDecimal value.
-
of
final JSONString of(String value)
Create a JSONString from a String value.
-
of
final JSONBoolean of(Boolean value)
Create a JSONBoolean from a Boolean value.
-
of
final JSONObject of(Pair<String, JSONValue> items)
-
parseNonNull
final JSONValue parseNonNull(String json)
-
parseArray
final JSONArray parseArray(String json)
-
parseObject
final JSONObject parseObject(String json)
Parse a String to a JSONObject.
-
parseLines
final JSONArray parseLines(String jsonLines)
-
toJSON
final String toJSON(JSONValue $self)
Convert the receiver JSONValue to a JSON string (
"null"if the receiver isnull).
-
appendTo
final Unit appendTo(JSONValue $self, Appendable a)
Append the receiver JSONValue as a JSON string (
"null"if the receiver isnull) to an Appendable.
-
outputTo
final Unit outputTo(JSONValue $self, IntConsumer out)
Output the receiver JSONValue as a JSON string (
"null"if the receiver isnull) to an IntConsumer (a character at a time).
-
output
@Deprecated(message = "renamed to outputTo", replaceWith = @ReplaceWith(imports = {"io.kjson.JSON.outputTo"}, expression = "outputTo(out)")) final Unit output(JSONValue $self, IntConsumer out)
Output the receiver JSONValue as a JSON string (
"null"if the receiver isnull) to an IntConsumer (a character at a time).
-
coOutputTo
final Unit coOutputTo(JSONValue $self, SuspendFunction1<Character, Unit> out)
Output the receiver JSONValue as a JSON string (
"null"if the receiver isnull) to a CoOutput (a character at a time).
-
coOutput
@Deprecated(message = "renamed to coOutputTo", replaceWith = @ReplaceWith(imports = {"io.kjson.JSON.coOutputTo"}, expression = "coOutputTo(out)")) final Unit coOutput(JSONValue $self, SuspendFunction1<Character, Unit> out)
Output the receiver JSONValue as a JSON string (
"null"if the receiver isnull) to a CoOutput (a character at a time).
-
appendJSONValue
final Appendable appendJSONValue(Appendable $self, JSONValue json)
Append a JSONValue as a JSON string (
"null"if the value isnull) to the receiver Appendable.
-
displayValue
final String displayValue(JSONValue $self, Integer maxString)
Convert the receiver JSONValue to a string suitable for use in human-readable messages.
-
elidedValue
final String elidedValue(JSONValue $self, Collection<String> exclude, Collection<String> include, String substitute)
Convert the receiver JSONValue to a string of JSON with nominated values elided (replaced by a substitute string).
-
asStringOr
final String asStringOr(JSONValue $self, Function1<JSONValue, String> alternative)
-
asUShortOr
final UShort asUShortOr(JSONValue $self, Function1<JSONValue, UShort> alternative)
-
asDecimalOr
final BigDecimal asDecimalOr(JSONValue $self, Function1<JSONValue, BigDecimal> alternative)
Get the receiver JSONValue as a BigDecimal if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception).
-
asBooleanOr
final Boolean asBooleanOr(JSONValue $self, Function1<JSONValue, Boolean> alternative)
-
asObjectOr
final JSONObject asObjectOr(JSONValue $self, Function1<JSONValue, JSONObject> alternative)
Get the receiver JSONValue as a JSONObject if compatible, or if not, return the result of the evaluation of the lambda (which may supply an alternative or throw an exception).
-
asStringOrError
final String asStringOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as a String, or throw a JSONTypeException if incorrect.
-
asLongOrError
final Long asLongOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as a Long, or throw a JSONTypeException if incorrect.
-
asIntOrError
final Integer asIntOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as an Int, or throw a JSONTypeException if incorrect.
-
asShortOrError
final Short asShortOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as a Short, or throw a JSONTypeException if incorrect.
-
asByteOrError
final Byte asByteOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as a Byte, or throw a JSONTypeException if incorrect.
-
asULongOrError
final ULong asULongOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as a ULong, or throw a JSONTypeException if incorrect.
-
asUIntOrError
final UInt asUIntOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as a UInt, or throw a JSONTypeException if incorrect.
-
asUShortOrError
final UShort asUShortOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as a UShort, or throw a JSONTypeException if incorrect.
-
asUByteOrError
final UByte asUByteOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as a UByte, or throw a JSONTypeException if incorrect.
-
asDecimalOrError
final BigDecimal asDecimalOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as a BigDecimal, or throw a JSONTypeException if incorrect.
-
asBooleanOrError
final Boolean asBooleanOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as a Boolean, or throw a JSONTypeException if incorrect.
-
asArrayOrError
final JSONArray asArrayOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as a JSONArray, or throw a JSONTypeException if incorrect.
-
asObjectOrError
final JSONObject asObjectOrError(JSONValue $self, String target, Object key, String nodeName)
Get the receiver JSONValue as a JSONObject, or throw a JSONTypeException if incorrect.
-
typeError
final Void typeError(JSONValue $self, String target, Object key, String nodeName)
Throw a JSONTypeException with the given parameters.
-
accept
final Unit accept(IntConsumer $self, CharSequence cs)
Output a CharSequence (e.g. a String) to an IntConsumer one character at a time.
-
getDefaultOutputBuilderSize
final Integer getDefaultOutputBuilderSize()
The default output buffer size for
toJSON()operations (JSONArrayandJSONObject)
-
setDefaultOutputBuilderSize
final Unit setDefaultOutputBuilderSize(Integer defaultOutputBuilderSize)
-
getAsString
final String getAsString(JSONValue $self)
-
getAsStringOrNull
final String getAsStringOrNull(JSONValue $self)
-
getAsLongOrNull
final Long getAsLongOrNull(JSONValue $self)
-
getAsIntOrNull
final Integer getAsIntOrNull(JSONValue $self)
-
getAsShort
final Short getAsShort(JSONValue $self)
-
getAsShortOrNull
final Short getAsShortOrNull(JSONValue $self)
-
getAsByteOrNull
final Byte getAsByteOrNull(JSONValue $self)
-
getAsULong
final ULong getAsULong(JSONValue $self)
-
getAsULongOrNull
final ULong getAsULongOrNull(JSONValue $self)
-
getAsUIntOrNull
final UInt getAsUIntOrNull(JSONValue $self)
-
getAsUShort
final UShort getAsUShort(JSONValue $self)
-
getAsUShortOrNull
final UShort getAsUShortOrNull(JSONValue $self)
-
getAsUByte
final UByte getAsUByte(JSONValue $self)
-
getAsUByteOrNull
final UByte getAsUByteOrNull(JSONValue $self)
-
getAsDecimal
final BigDecimal getAsDecimal(JSONValue $self)
-
getAsDecimalOrNull
final BigDecimal getAsDecimalOrNull(JSONValue $self)
-
getAsBoolean
final Boolean getAsBoolean(JSONValue $self)
-
getAsBooleanOrNull
final Boolean getAsBooleanOrNull(JSONValue $self)
-
getAsArray
final JSONArray getAsArray(JSONValue $self)
-
getAsArrayOrNull
final JSONArray getAsArrayOrNull(JSONValue $self)
-
getAsObject
final JSONObject getAsObject(JSONValue $self)
-
getAsObjectOrNull
final JSONObject getAsObjectOrNull(JSONValue $self)
-
-
-
-