convert json into map in java example

Solutions on MaxInterview for convert json into map in java example by the best coders in the world

showing results for - "convert json into map in java example"
Alessio
19 Jul 2017
1public static Map<String, Object> jsonToMap(JSONObject json) throws JSONException {
2    Map<String, Object> retMap = new HashMap<String, Object>();
3
4    if(json != JSONObject.NULL) {
5        retMap = toMap(json);
6    }
7    return retMap;
8}
9
10public static Map<String, Object> toMap(JSONObject object) throws JSONException {
11    Map<String, Object> map = new HashMap<String, Object>();
12
13    Iterator<String> keysItr = object.keys();
14    while(keysItr.hasNext()) {
15        String key = keysItr.next();
16        Object value = object.get(key);
17
18        if(value instanceof JSONArray) {
19            value = toList((JSONArray) value);
20        }
21
22        else if(value instanceof JSONObject) {
23            value = toMap((JSONObject) value);
24        }
25        map.put(key, value);
26    }
27    return map;
28}
29
30public static List<Object> toList(JSONArray array) throws JSONException {
31    List<Object> list = new ArrayList<Object>();
32    for(int i = 0; i < array.length(); i++) {
33        Object value = array.get(i);
34        if(value instanceof JSONArray) {
35            value = toList((JSONArray) value);
36        }
37
38        else if(value instanceof JSONObject) {
39            value = toMap((JSONObject) value);
40        }
41        list.add(value);
42    }
43    return list;
44}
queries leading to this page
converting json to a mapconvert map into jsonconvert json to mapconvert json key value in mapjava convert json to mapjava object to json mapmap into jsonmap an object to json string in javajson object to map javahow to convert map to jsonobject in javaobjectmapper string to maphow to map json object into java object in javahow to map json to java objectconvert string json to map javajava create map from json stringjava json to hashmapconvert json object to map in javahow to write map to json filejava map to json stringjava code to convert map to json stringjson to hashmap java using objectmapperobject to json map javahow to map a json to object in javajson dtring to map javajava jackson parse map to jsonconvert json string to list of map in javamap json to jsonmap in json exampleget map from json jabvahow map a simple json textconvert json string into java mapjackson load json to mapjava convert json from hashmapconvert java map to jsonhow to convert map to json object in javajava map to jsonjava convert string json to hashmapconvet map to json string in javajava create a json from mapconvert json string to mapjson stringify hasmap javaconvert map to json string javastring json to map javaparse json string to map in javaconvert map to jsonconvert json response to map in javahow to turn json into mapjson to map in java using org jsonjava json parse into maphow to convert a json string to a map in javajson parse hashmap javaconverting json object to a mapread json as map javajava cast map to jsonconvert json to list of map javaconvert a json string to map in javahow to map json object into java objectmap value to json javahow to map jsonconvert map into json object javahow to convert json object to map in javajava json to mapjava map to json mapmap convert to jsonhow to convert json string into map in javamap 3cstring 2c object 3e to json in javajava map from jsonconvert map into a json javajackson json to hashmap how to convert json to hashmap in javahow to save map in json javaconvert json to hashmap javaconvert json to map in javaconverting a json object into java mapjava map to json objectconvert json string to hashmap javamap into json javajson to map 3cstring 2c string 3e in java 5cconvert json map to java objectconvert json string to list of hashmap in javajava json to hasmapjava object map to jsonhow to convert map string object to json in javajava to string of map to jsonjava 3amap to jsonhow to convert json data to map in javahow to write json string to java mapjava convert map to jsonhow to map json to java object in javamap to json string javaconvert json into map in java examplemap json to object javahow to put all json data into a map javahow to convert json to java mapto map json string values to object in javaconvert map to json string javahow to change json to map in javafrom json to map javajava parsing json as mapmap over json and convert to json javabind map to json elementhow to convert map 3cstring 2cobject 3e into json nodehow to turn a map into a jsonjava map string to json map to json object javajson object to map conversion in javahow to map java object to json how to convert json file to map in javahow to convert json into map in javaconvert a map to json javagolang json to mapmap json to map javajackson objectmapper string to mapjackson to convert json object to mapjson map to java mapjackson convert json in mapjava convert map to json stringconvert json string to map in javaconvert from json to maphow to convert json array to map in javamap to json object in javaconvert map to json javaconvert a map to jsoncreate json file from map javaconvert object map to jsonparse json string to map javaconvert json array into map in javamap to json javaconvert json to map in java using jacksonconverting map to jsonconvert json object to map 3cstring 2cobject 3e 2b javaconverting json to java mapconvert json format string to map in javajackson json hashmap examplejson string to map in javajackson objectmapper from string to mapjackson string to maphow to convert java map object to json stringjava map value to json stringcreate map from json string javaconverting jsonobject to map in javajava jackson convert map to jsonjson to hashmap javajson string to maphow to convert json string to map in javajson to map in javahow to convert a json to map in javastring to map castingjson object to maphow to convert map to json in javahow to convert json object to map in java 8from json object to map javahow to pass map in json response javaconvert map 28 29 to jsonconvert map to json objectjson string to hashmap java 8transform json to dictionary javahow to convert map into json in java using jacksonjava map convert to jsonfastest way to convert json string to map javajava change jsonarray into mapjson to map javahow to convert json string to java maphow to convert json to hashmapjava json string to mapconvert java map object to jsonjson to hashmapjson to map in java 5cconvert json to hashmap in javajava string json to maphow to map object to json in javajava map convert to json string in javamap json to java objecthow to convert jsonobject to map in javahow to write hashmap to json in javconvert map to json in javajava json object to mapjson to mapjson into mapjavahow to convert json to map in javaconvert json string to map java json to java mapjson string to map javaconvert map to json and write to file in javaconvert json into map in java example