Class JsonObj


  • public class JsonObj
    extends java.lang.Object
    This class consists exclusively of static utility methods for processing JSON objects.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object get​(java.lang.String obj, java.lang.String key, java.lang.String default_value)
      Retrieve deep/nested value from a JSON Object.
      static java.lang.Object get​(org.json.JSONObject obj, java.lang.String key, java.lang.String default_value)
      Retrieve deep/nested value from a JSON Object.
      static java.lang.String set​(java.lang.String obj, java.lang.String key, java.lang.Object value)
      Set a key-value pair deep within a JSON Object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • get

        public static java.lang.Object get​(java.lang.String obj,
                                           java.lang.String key,
                                           java.lang.String default_value)
        Retrieve deep/nested value from a JSON Object.
        Parameters:
        obj - String serialized JSON object to retrieve value from.
        key - The key for fetching value from the object. Deep/nested path is represented by dot notation.
        default_value - Default value to return if the key was not found or in case of any error in parsing the object.
        Returns:
        The value
      • get

        public static java.lang.Object get​(org.json.JSONObject obj,
                                           java.lang.String key,
                                           java.lang.String default_value)
        Retrieve deep/nested value from a JSON Object.
        Parameters:
        obj - The JSONObject to retrieve value from.
        key - The key for fetching value from the object. Deep/nested path is represented by dot notation.
        default_value - Default value to return if the key was not found or in case of any error in parsing the object.
        Returns:
        The value
      • set

        public static java.lang.String set​(java.lang.String obj,
                                           java.lang.String key,
                                           java.lang.Object value)
        Set a key-value pair deep within a JSON Object.
        Parameters:
        obj - String serialized JSON object to insert value into.
        key - The key for inserting value into the object. Deep/nested path is represented by dot notation. Unavailable object path is created.
        value - An object which is the value. It should be of one of these types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String, or the JSONObject.NULL object.
        Returns:
        The String serialized JSON object with the key-value pair inserted.