convert json into map in java example

public static Map<String, Object> jsonToMap(JSONObject json) throws JSONException {
    Map<String, Object> retMap = new HashMap<String, Object>();

    if(json != JSONObject.NULL) {
        retMap = toMap(json);
    }
    return retMap;
}

public static Map<String, Object> toMap(JSONObject object) throws JSONException {
    Map<String, Object> map = new HashMap<String, Object>();

    Iterator<String> keysItr = object.keys();
    while(keysItr.hasNext()) {
        String key = keysItr.next();
        Object value = object.get(key);

        if(value instanceof JSONArray) {
            value = toList((JSONArray) value);
        }

        else if(value instanceof JSONObject) {
            value = toMap((JSONObject) value);
        }
        map.put(key, value);
    }
    return map;
}

public static List<Object> toList(JSONArray array) throws JSONException {
    List<Object> list = new ArrayList<Object>();
    for(int i = 0; i < array.length(); i++) {
        Object value = array.get(i);
        if(value instanceof JSONArray) {
            value = toList((JSONArray) value);
        }

        else if(value instanceof JSONObject) {
            value = toMap((JSONObject) value);
        }
        list.add(value);
    }
    return list;
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to convert json data to map in java how to convert map to jsonobject in java how to map java object to json convert json response to map in java java convert map to json string FROM JSON TO MAP JAVA how to map object to json in java how to convert java map object to json string converting jsonobject to map in java convert json map to java object how to write json string to Java map java object to json map java map convert to json string in java how to map json to java object in java how to map json to java object json to map in java using org.json how to convert json object to map in java how to map json object into java object in java how to map json object into java object convert map into json java to string of map to json java map to json object convert json object to Map&lt;String,object&gt; + java how to convert json array to map in java how to map a json to object in java how to convert map into json in java using jackson java map convert to json string json to map java map into json java map to json object java json to map&lt;String, String&gt; in java\ json to map in java\ json map to java map convert map into json object java java map to json string convert a json string to map in java map over json and convert to json java how to convert JSON object to map in java 8 json object to map java how to convert json to map in java convert map to json java java convert json from hashmap map an object to json string in java convert map to json string java map to json object in java java jackson convert map to json fastest way to convert json string to map java convert json array into map in java converting json to java map how to turn a map into a json java convert json to map java convert map to json java object map to json how to convert json string to java map converting map to json convert map into a json java from json object to map java map json to java object how to convert map to json object in java convert json object to map in java how to convert jsonobject to map in java convert a map to json java convert java map to json java map value to json string convert string json to map java how to convert json string to map in java how to convert map to json in java jackson convert json in map convert json format string to map in java convert json to hashmap java parse json string to map java jackson objectmapper from string to map map convert to json convert json string to list of map in java how to map json how map a simple json text convert json string to map in java convert json to map in java how to put all json data into a map java how to convert a json to map in java map in json example jackson objectmapper string to map string to map casting json object to map convert a map to json how to write map to json file golang json to map java json to map map to json string java jackson json to hashmap java create a json from map read json as map java convert json into map in java example json string to hashmap java 8 map to json java parse json string to map in java convert json string to list of hashmap in java to map json string values to object in java java jackson parse map to json json to map convert map to json in java map json to json java parsing json as map create json file from map java java json parse into map objectmapper string to map java json string to map how to convert a json string to a map in java json to hashmap java using objectmapper json string to map convert json to map Json dtring to map java how to convert json to java map java convert string json to hashmap java map string to json convert object map to json converting json to a map convert map to json and write to file in java java json to hashmap json to map java jackson load json to map how to convert json to hashmap how to pass map in json response java jackson string to map json to hashmap convert json string to map convert json to map in java using jackson bind map to json element json to java map convert json string to hashmap java json into mapjava json stringify hasmap java transform json to dictionary java jackson to convert json object to map converting json object to a map how to convert map string object to json in java how to change json to map in java how to save map in json java how to convert json to hashmap in java how to write hashmap to json in jav convert json to hashmap in java java json to hasmap json parse hashmap java json to map in java convert json key value in map json to hashmap java convert Map() to json convert json to list of map java json object to map conversion in java jackson json hashmap example java map to json how to convert map&lt;string,object&gt; into json node json string to map java convert map to json object get map from json jabva convert map to json
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source