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 JSONArray
asJSONArray()
Return the JSONNode as a JSONArraydefault JSONObject
asJSONObject()
Return the JSONNode as a JSONObjectdefault boolean
isArray()
Interrogate if the JSONNode is a JSONArraydefault boolean
isEquivalent(JSONNode other)
Compares against another JSONNode for equivalence.default boolean
isObject()
Interrogate if the JSONNode is a JSONObjectString
prettyPrint()
Pretty print the JSON as a stringString
prettyPrint(int indent)
Pretty print JSON string with specified indentsdefault JSONArray
select(String jsonPath)
Select a value from the JSONNode using a JSON-Path expression.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.default JSONArray
select(String jsonPath, com.jayway.jsonpath.Option... options)
Select a value from the JSONNode using a JSON-Path expression.default <T> T
selectValue(String jsonPath)
Select a single value from a JSONPath expressiondefault <T> T
selectValue(String jsonPath, com.jayway.jsonpath.Criteria criteria, com.jayway.jsonpath.Option... options)
default <T> T
selectValue(String jsonPath, com.jayway.jsonpath.Option... options)
String
toJSONString()
Return as a JSON Stringdefault void
write(File file)
Write the current node to a Filedefault void
write(File outputFile, boolean prettyPrint)
Write the current node with optional pretty printingdefault void
write(OutputStream out)
Write the current node to an OutputStreamdefault void
write(OutputStream out, boolean prettyPrint)
Write the current node with optional pretty printingdefault void
write(Writer writer)
Write the current node to a Writerdefault void
write(Writer writer, boolean prettyPrint)
Write the current node with optional pretty printingdefault void
write(Path outputPath)
Write the current node to a Pathdefault void
write(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
-