Package adams.data.json
Class JsonHelper
- java.lang.Object
-
- adams.data.json.JsonHelper
-
public class JsonHelper extends Object
Helper class for JSON.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
-
-
Constructor Summary
Constructors Constructor Description JsonHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static net.minidev.json.JSONObjectfromMap(Map map)Turns the map into a JSON object.static Objectparse(File file, LoggingSupporter logging)Parses the JSON file.static Objectparse(Reader reader)Parses the JSON via a Reader.static Objectparse(String json, LoggingSupporter logging)Parses the JSON String.static StringprettyPrint(com.google.gson.JsonElement json)Generates pretty printed JSON.static StringprettyPrint(String json)Generates pretty printed JSON.static StringprettyPrint(net.minidev.json.JSONAware json)Generates pretty printed JSON.static Object[]toArray(net.minidev.json.JSONArray array)Turns the JSON array into an object array.static ObjecttoJSON(Object value)Turns the object into a JSON object, if necessary.static List<Object>toList(net.minidev.json.JSONArray array)Turns the JSON array into an object list.static Map<String,Object>toMap(net.minidev.json.JSONObject object, boolean arraysAsList)Turns the JSON object into a map.
-
-
-
Method Detail
-
parse
public static Object parse(Reader reader) throws Exception
Parses the JSON via a Reader.- Parameters:
reader- the reader to use- Returns:
- the parsed JSON
- Throws:
Exception- if parsing fails
-
parse
public static Object parse(String json, LoggingSupporter logging)
Parses the JSON String.- Parameters:
json- the string to parselogging- for logging error messages, uses stderr if null- Returns:
- the object, null if failed to parse
-
parse
public static Object parse(File file, LoggingSupporter logging)
Parses the JSON file.- Parameters:
file- the file to parselogging- for logging error messages, uses stderr if null- Returns:
- the object, null if failed to parse
-
prettyPrint
public static String prettyPrint(net.minidev.json.JSONAware json)
Generates pretty printed JSON.- Parameters:
json- the JSON element to convert- Returns:
- the pretty string
-
prettyPrint
public static String prettyPrint(com.google.gson.JsonElement json)
Generates pretty printed JSON.- Parameters:
json- the JSON element to convert- Returns:
- the pretty string
-
prettyPrint
public static String prettyPrint(String json)
Generates pretty printed JSON.- Parameters:
json- the JSON string to convert- Returns:
- the pretty string
-
toJSON
public static Object toJSON(Object value)
Turns the object into a JSON object, if necessary.- Parameters:
value- the value associated with the key
-
toArray
public static Object[] toArray(net.minidev.json.JSONArray array)
Turns the JSON array into an object array.- Parameters:
array- the array to convert- Returns:
- the generated array
-
toList
public static List<Object> toList(net.minidev.json.JSONArray array)
Turns the JSON array into an object list.- Parameters:
array- the array to convert- Returns:
- the generated list
-
toMap
public static Map<String,Object> toMap(net.minidev.json.JSONObject object, boolean arraysAsList)
Turns the JSON object into a map.- Parameters:
object- the object to convert- Returns:
- the generated map
-
fromMap
public static net.minidev.json.JSONObject fromMap(Map map)
Turns the map into a JSON object.- Parameters:
map- the map to convert- Returns:
- the generated JSON object
-
-