Package org.ghotibeaun.json
Interface JSONNode
- All Superinterfaces:
Comparable<JSONNode>,Serializable
- All Known Subinterfaces:
JSONArray,JSONListNode,JSONMapNode,JSONObject
public interface JSONNode extends Serializable, Comparable<JSONNode>
Base interface for JSON entities
- Author:
- Jim Earley
-
Method Summary
Modifier and Type Method Description default JSONArrayasJSONArray()Return the JSONNode as a JSONArraydefault JSONObjectasJSONObject()Return the JSONNode as a JSONObjectdefault booleanisArray()Interrogate if the JSONNode is a JSONArraydefault booleanisEquivalent(JSONNode other)Compares against another JSONNode for equivalence.default booleanisObject()Interrogate if the JSONNode is a JSONObjectStringprettyPrint()Pretty print the JSON as a stringStringprettyPrint(int indent)Pretty print JSON string with specified indentsdefault JSONArrayselect(String jsonPath)Select a value from the JSONNode using a JSON-Path expression.default JSONArrayselect(String jsonPath, com.jayway.jsonpath.Criteria criteria, com.jayway.jsonpath.Option... options)Select a value from the JSONNode using a JSON-Path expression.default JSONArrayselect(String jsonPath, com.jayway.jsonpath.Option... options)Select a value from the JSONNode using a JSON-Path expression.default <T> TselectValue(String jsonPath)Select a single value from a JSONPath expressiondefault <T> TselectValue(String jsonPath, com.jayway.jsonpath.Criteria criteria, com.jayway.jsonpath.Option... options)default <T> TselectValue(String jsonPath, com.jayway.jsonpath.Option... options)StringtoJSONString()Return as a JSON Stringdefault voidwrite(File file)Write the current node to a Filedefault voidwrite(File outputFile, boolean prettyPrint)Write the current node with optional pretty printingdefault voidwrite(OutputStream out)Write the current node to an OutputStreamdefault voidwrite(OutputStream out, boolean prettyPrint)Write the current node with optional pretty printingdefault voidwrite(Writer writer)Write the current node to a Writerdefault voidwrite(Writer writer, boolean prettyPrint)Write the current node with optional pretty printingdefault voidwrite(Path outputPath)Write the current node to a Pathdefault voidwrite(Path outputPath, boolean prettyPrint)Write the current node with optional pretty printingMethods inherited from interface java.lang.Comparable
compareTo
-
Method Details
-
toJSONString
String toJSONString()Return as a JSON String- Returns:
- String representation of the JSONNode. Results are serialized as a non-formatted string
-
prettyPrint
String prettyPrint()Pretty print the JSON as a string- Returns:
- pretty printed JSON string
-
prettyPrint
Pretty print JSON string with specified indents- Parameters:
indent- the number of spaces to indent- Returns:
- the pretty printed JSON string
-
isArray
default boolean isArray()Interrogate if the JSONNode is a JSONArray- Returns:
- true if it is a JSONArray; false otherwise
-
isObject
default boolean isObject()Interrogate if the JSONNode is a JSONObject- Returns:
- true if it is a JSONObject; false otherwise
-
asJSONObject
Return the JSONNode as a JSONObject- Returns:
- a JSONObject representation of the JSONNode
-
asJSONArray
Return the JSONNode as a JSONArray- Returns:
- the node cast as a JSONArray
-
select
Select a value from the JSONNode using a JSON-Path expression.This is a wrapper around the JSONPath API
- Parameters:
jsonPath- the JSON-Path expression- Returns:
- A JSONArray of values.
-
select
Select a value from the JSONNode using a JSON-Path expression.This is a wrapper around the JSONPath API
- Parameters:
jsonPath- the JSON-Path expressionoptions- One or more options to implement on the JSONPath query- Returns:
- A JSONArray of values
-
select
default JSONArray select(String jsonPath, com.jayway.jsonpath.Criteria criteria, com.jayway.jsonpath.Option... options)Select a value from the JSONNode using a JSON-Path expression.This is a wrapper around the JSONPath API
- Parameters:
jsonPath- the JSON-Path expressionoptions- One or more options to implement on the JSONPath query- Returns:
- A JSONArray of values
-
selectValue
Select a single value from a JSONPath expression- Parameters:
jsonPath- the JSONPath expression- Returns:
- the typed value (or null). For primitive Java types, users should take care to understand the data
-
selectValue
-
selectValue
default <T> T selectValue(String jsonPath, com.jayway.jsonpath.Criteria criteria, com.jayway.jsonpath.Option... options) -
write
Write the current node to an OutputStream- Parameters:
out- the OutputStream
-
write
Write the current node to a Path- Parameters:
outputPath- the Path
-
write
Write the current node to a Writer- Parameters:
writer- the Writer
-
write
Write the current node to a File- Parameters:
file- the File
-
write
Write the current node with optional pretty printing- Parameters:
out- the OutputStreamprettyPrint- true if pretty printing is enabled; false otherwise
-
write
Write the current node with optional pretty printing- Parameters:
out- the PathprettyPrint- true if pretty printing is enabled; false otherwise
-
write
Write the current node with optional pretty printing- Parameters:
out- the FileprettyPrint- true if pretty printing is enabled; false otherwise
-
write
Write the current node with optional pretty printing- Parameters:
out- the WriterprettyPrint- true if pretty printing is enabled; false otherwise
-
isEquivalent
Compares against another JSONNode for equivalence. Equivalance is true if:- Each JSONNode is of the same type
- For JSONObjects:
- Must contain the same keys, though not necessarily in any order
- Each key's value must be equivalent
- For JSONArrays:
- List order does matter
- Each value in the list must be equivalent
- Parameters:
other- The other JSONNode to compare against- Returns:
- true if both JSONNodes are equivalent; false otherwise
-