Package org.kissweb
Class JsonPath
java.lang.Object
org.kissweb.JsonPath
This class provides a variety of features on top of the functionality provided by org.json.
In addition to being able to parse a string into a json object, the json object can also be obtained
from a file. Once the json object is obtained, embedded elements may be indexed similar to XPath thus
providing an easy method of destructuring a complex json object. Lastly, rather than throw an exception
when a data item is missing, these methods return null.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BooleangetBoolean(String delimiter, org.json.JSONObject jobj, String path) Traverse an object returning the Boolean referenced bypath.static BooleangetBoolean(org.json.JSONObject jobj, String path) Traverse an object returning the Boolean referenced bypath.static CharactergetCharacter(String delimiter, org.json.JSONObject jobj, String path) Traverse an object returning the Character referenced bypath.static CharactergetCharacter(org.json.JSONObject jobj, String path) Traverse an object returning the Character referenced bypath.static IntegerTraverse an object returning the Integer date referenced bypath.static IntegerTraverse an object returning the Integer date referenced bypath.static DoubleTraverse an object returning the Double referenced bypath.static DoubleTraverse an object returning the Double referenced bypath.static IntegergetInteger(String delimiter, org.json.JSONObject jobj, String path) Traverse an object returning the Integer referenced bypath.static IntegergetInteger(org.json.JSONObject jobj, String path) Traverse an object returning the Integer referenced bypath.static org.json.JSONArraygetJSONArray(String delimiter, org.json.JSONObject jobj, String path) Traverse an object returning the JSONArray referenced bypath.static org.json.JSONArraygetJSONArray(org.json.JSONObject jobj, String path) Traverse an object returning the JSONArray referenced bypath.static LongTraverse an object returning the Long referenced bypath.static LongTraverse an object returning the Long referenced bypath.static org.json.JSONObjectTraverse an object returning the sub-object referenced bypath.static org.json.JSONObjectTraverse an object returning the sub-object referenced bypath.static StringTraverse an object returning the String referenced bypath.static StringTraverse an object returning the String referenced bypath.static voidstatic org.json.JSONObjectThis takes a JSON string or a file name (containing JSON) and returns a JSON object.
-
Constructor Details
-
JsonPath
public JsonPath()
-
-
Method Details
-
toJson
This takes a JSON string or a file name (containing JSON) and returns a JSON object.
If in a string, the string must start with "{" or space character- Parameters:
str- the json string or file name containing a json string- Returns:
- Throws:
IOException
-
getObject
public static org.json.JSONObject getObject(String delimiter, org.json.JSONObject jobj, String path) Traverse an object returning the sub-object referenced bypath.- Parameters:
delimiter- the delimiter used inpathto delimit the each path sub-partjobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the json object being referenced by path or null if not found
-
getObject
Traverse an object returning the sub-object referenced bypath. The delimiter used inpathis a period.- Parameters:
jobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the json object being referenced by path or null if not found
-
getString
Traverse an object returning the String referenced bypath.- Parameters:
delimiter- the delimiter used inpathto delimit the each path sub-partjobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the String being referenced by path or null if not found
-
getString
Traverse an object returning the String referenced bypath. The delimiter used inpathis a period.- Parameters:
jobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the String being referenced by path or null if not found
-
getInteger
Traverse an object returning the Integer referenced bypath.- Parameters:
delimiter- the delimiter used inpathto delimit the each path sub-partjobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the Integer being referenced by path or null if not found
-
getInteger
Traverse an object returning the Integer referenced bypath. The delimiter used inpathis a period.- Parameters:
jobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the Integer being referenced by path or null if not found
-
getDouble
Traverse an object returning the Double referenced bypath.- Parameters:
delimiter- the delimiter used inpathto delimit the each path sub-partjobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the Double being referenced by path or null if not found
-
getDouble
Traverse an object returning the Double referenced bypath. The delimiter used inpathis a period.- Parameters:
jobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the Double being referenced by path or null if not found
-
getJSONArray
public static org.json.JSONArray getJSONArray(String delimiter, org.json.JSONObject jobj, String path) Traverse an object returning the JSONArray referenced bypath.- Parameters:
delimiter- the delimiter used inpathto delimit the each path sub-partjobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the JSONArray being referenced by path or null if not found
-
getJSONArray
Traverse an object returning the JSONArray referenced bypath. The delimiter used inpathis a period.- Parameters:
jobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the JSONArray being referenced by path or null if not found
-
getBoolean
Traverse an object returning the Boolean referenced bypath.- Parameters:
delimiter- the delimiter used inpathto delimit the each path sub-partjobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the Boolean being referenced by path or null if not found
-
getBoolean
Traverse an object returning the Boolean referenced bypath. The delimiter used inpathis a period.- Parameters:
jobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the Boolean being referenced by path or null if not found
-
getLong
Traverse an object returning the Long referenced bypath.- Parameters:
delimiter- the delimiter used inpathto delimit the each path sub-partjobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the Long being referenced by path or null if not found
-
getLong
Traverse an object returning the Long referenced bypath. The delimiter used inpathis a period.- Parameters:
jobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the Long being referenced by path or null if not found
-
getCharacter
Traverse an object returning the Character referenced bypath.
If the field contains mor than one character, the first is returned.- Parameters:
delimiter- the delimiter used inpathto delimit the each path sub-partjobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the Character being referenced by path or null if not found
-
getCharacter
Traverse an object returning the Character referenced bypath. The delimiter used inpathis a period.
If the field contains mor than one character, the first is returned.- Parameters:
jobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the Character being referenced by path or null if not found
-
getDate
Traverse an object returning the Integer date referenced bypath.
The Integer date returned is of the form YYYYMMDD. So, 6/8/2018 would be returned as 20180608. A null is returned if the data cannot be obtained.- Parameters:
delimiter- the delimiter used inpathto delimit the each path sub-partjobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the Integer date being referenced by path or null if not found
-
getDate
Traverse an object returning the Integer date referenced bypath. The delimiter used inpathis a period.
The Integer date returned is of the form YYYYMMDD. So, 6/8/2018 would be returned as 20180608. A null is returned if the data cannot be obtained.- Parameters:
jobj- the initial json objectpath- a string indicating the path to the desired element- Returns:
- the Integer date being referenced by path or null if not found
-
main
- Throws:
IOException
-