org.apache.pivot.json
Class JSON

java.lang.Object
  extended by org.apache.pivot.json.JSON

public class JSON
extends Object

Contains utility methods for working with JSON or JSON-like data structures.


Constructor Summary
JSON()
           
 
Method Summary
static boolean containsKey(Object root, String path)
          Tests the existence of a path in a given object.
static Object get(Object root, String path)
          Returns the value at the given path.
static Boolean getBoolean(Object root, String path)
          Returns the value at the given path as a boolean.
static Double getDouble(Object root, String path)
          Returns the value at the given path as a double.
static Float getFloat(Object root, String path)
          Returns the value at the given path as a float.
static Integer getInteger(Object root, String path)
          Returns the value at the given path as an integer.
static List<?> getList(Object root, String path)
          Returns the value at the given path as a list.
static Long getLong(Object root, String path)
          Returns the value at the given path as a long.
static Map<String,?> getMap(Object root, String path)
          Returns the value at the given path as a map.
static Number getNumber(Object root, String path)
          Returns the value at the given path as a number.
static Short getShort(Object root, String path)
          Returns the value at the given path as a short.
static String getString(Object root, String path)
          Returns the value at the given path as a string.
static Object put(Object root, String path, Object value)
          Sets the value at the given path.
static Object remove(Object root, String path)
          Removes the value at the given path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSON

public JSON()
Method Detail

get

public static Object get(Object root,
                         String path)
Returns the value at the given path.

Parameters:
root - The root object; must be an instance of Map or List.
path - The path to the value, in JavaScript path notation.
Returns:
The value at the given path.

getString

public static String getString(Object root,
                               String path)
Returns the value at the given path as a string.

Parameters:
root -
path -
See Also:
get(Object, String)

getNumber

public static Number getNumber(Object root,
                               String path)
Returns the value at the given path as a number.

Parameters:
root -
path -
See Also:
get(Object, String)

getShort

public static Short getShort(Object root,
                             String path)
Returns the value at the given path as a short.

Parameters:
root -
path -
See Also:
get(Object, String)

getInteger

public static Integer getInteger(Object root,
                                 String path)
Returns the value at the given path as an integer.

Parameters:
root -
path -
See Also:
get(Object, String)

getLong

public static Long getLong(Object root,
                           String path)
Returns the value at the given path as a long.

Parameters:
root -
path -
See Also:
get(Object, String)

getFloat

public static Float getFloat(Object root,
                             String path)
Returns the value at the given path as a float.

Parameters:
root -
path -
See Also:
get(Object, String)

getDouble

public static Double getDouble(Object root,
                               String path)
Returns the value at the given path as a double.

Parameters:
root -
path -
See Also:
get(Object, String)

getBoolean

public static Boolean getBoolean(Object root,
                                 String path)
Returns the value at the given path as a boolean.

Parameters:
root -
path -
See Also:
get(Object, String)

getList

public static List<?> getList(Object root,
                              String path)
Returns the value at the given path as a list.

Parameters:
root -
path -
See Also:
get(Object, String)

getMap

public static Map<String,?> getMap(Object root,
                                   String path)
Returns the value at the given path as a map.

Parameters:
root -
path -
See Also:
get(Object, String)

put

public static Object put(Object root,
                         String path,
                         Object value)
Sets the value at the given path.

Parameters:
root -
path -
value -
Returns:
The value previously associated with the path.

remove

public static Object remove(Object root,
                            String path)
Removes the value at the given path.

Parameters:
root -
path -
Returns:
The value that was removed.

containsKey

public static boolean containsKey(Object root,
                                  String path)
Tests the existence of a path in a given object.

Parameters:
root -
path -
Returns:
true if the path exists; false, otherwise.