Package org.javalite.json
Class JSONMap
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,Object>
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJSONMap()
Default constructor.Converts the String into a JSONMap.Creates an instance from the array, where odd arguments are map keys and the even are values.Creates an instance from the map. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKeyBy(String attributePath)
Returns true if object exists.getBigDecimal(String attributePath)
getBoolean(String attributePath)
Returns an object deep from the structure of a JSON document.getInteger(String attributePath)
Returns a list deep from the structure of JSON document.Returns a map deep from the structure of a JSON document.Put the object deep into the structure of the JSON document.Put an object deep to the structure of a JSON document.toJSON()
toJSON(boolean pretty)
toString()
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode
-
Field Details
-
KEY_DELIMITER
- See Also:
- Constant Field Values
-
-
Constructor Details
-
JSONMap
Creates an instance from the map. All keys will be converted to strings.- Parameters:
map
- source map
-
JSONMap
Creates an instance from the array, where odd arguments are map keys and the even are values.- Parameters:
keysAndValues
- keys and
-
JSONMap
Converts the String into a JSONMap.- Parameters:
jsonString
- JSON Object document as string.
-
JSONMap
public JSONMap()Default constructor.
-
-
Method Details
-
getBy
Returns an object deep from the structure of a JSON document.{ "university": { students : { "mary" : { "first_name": "Mary", "last_name": "Smith", }, "joe" : { "first_name": "Joe", "last_name": "Shmoe", } } } }
- Parameters:
attributePath
- accepts a dot-delimited format: "university.students.joe" where every entry except the last one must be a map- Returns:
- an object from the depths of the JSON structure.
-
containsKeyBy
Returns true if object exists.- Parameters:
attributePath
- accepts a dot-delimited format: "university.students.joe" where every entry except the last one must be a map- Returns:
- true if exists
-
putBy
Put the object deep into the structure of the JSON document.- Parameters:
attributePath
- accepts a dot-delimited format: "university.students.joe" where every entry except the last one must be a mapvalue
- value- Returns:
- previous value
-
putBy
Put an object deep to the structure of a JSON document.- Parameters:
attributePath
- accepts a dot-delimited format: "university.students.joe" where every entry except the last one must be a mapvalue
- valuecreate
- create intermediate objects if true- Returns:
- previous value
-
getMap
Returns a map deep from the structure of a JSON document.{ "university": { students : { "mary" : { "first_name": "Mary", "last_name": "Smith", }, "joe" : { "first_name": "Joe", "last_name": "Shmoe", } } } }
- Parameters:
attributePath
- accepts a dot-delimited format: "university.students.joe" where every entry must be a map- Returns:
- a map from the depths of the JSON structure.
-
getList
Returns a list deep from the structure of JSON document.{ "university": { students : ["mary", joe] } }
- Parameters:
attributePath
- accepts a dot-delimited format: "university.students" where every entry must be a map- Returns:
- list from the depths of the JSON structure.
-
getBoolean
- Parameters:
attributePath
- accepts a dot-delimited format: "university.students" where every entry must be a map.
-
getBigDecimal
- Parameters:
attributePath
- accepts a dot-delimited format: "university.students" where every entry must be a map.
-
getDate
- Parameters:
attributePath
- accepts a dot-delimited format: "university.students" where every entry must be a map.
-
getDouble
- Parameters:
attributePath
- accepts a dot-delimited format: "university.students" where every entry must be a map.
-
getFloat
- Parameters:
attributePath
- accepts a dot-delimited format: "university.students" where every entry must be a map.
-
getInteger
- Parameters:
attributePath
- accepts a dot-delimited format: "university.students" where every entry must be a map.
-
getLong
- Parameters:
attributePath
- accepts a dot-delimited format: "university.students" where every entry must be a map.
-
getShort
- Parameters:
attributePath
- accepts a dot-delimited format: "university.students" where every entry must be a map.
-
getString
- Parameters:
attributePath
- accepts a dot-delimited format: "university.students" where every entry must be a map.
-
toString
- Overrides:
toString
in classAbstractMap<String,Object>
- Returns:
- a JSON representation of this object
-
toJSON
- Parameters:
pretty
- - true for formatted JSON.- Returns:
- a JSON representation of this object
-
toJSON
- Returns:
- a JSON representation of this object
-