- JSON.simple - Home
- JSON.simple - Overview
- JSON.simple - Environment Setup
- JSON.simple - JAVA Mapping
- Decoding Examples
- Escaping Special Characters
- JSON.simple - Using JSONValue
- JSON.simple - Exception Handling
- JSON.simple - Container Factory
- JSON.simple - Content Handler
- Encoding Examples
- JSON.simple - Encode JSONObject
- JSON.simple - Encode JSONArray
- Merging Examples
- JSON.simple - Merging Objects
- JSON.simple - Merging Arrays
- Combination Examples
- JSON.simple - Primitive, Object, Array
- JSON.simple - Primitive, Map, List
- Primitive, Object, Map, List
- Customization Examples
- JSON.simple - Customized Output
- Customized Output Streaming
- JSON.simple Useful Resources
- JSON.simple - Quick Guide
- JSON.simple - Useful Resources
- JSON.simple - Discussion
JSON.simple - Primitive, Object, Map, List
Using JSONValue object, we can create a JSON which comprises of primitives, Object, Map and List.
Following example illustrates the above concept.
Example
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
class JsonDemo {
public static void main(String[] args) throws IOException {
JSONObject obj = new JSONObject();
Map m1 = new LinkedHashMap();
m1.put("k11","v11");
m1.put("k12","v12");
m1.put("k13", "v13");
List l1 = new LinkedList();
l1.add(new Integer(100));
obj.put("m1", m1);
obj.put("l1", l1);
String jsonString = JSONValue.toJSONString(obj);
System.out.println(jsonString);
}
}
Output
{"m1":{"k11":"v11","k12":"v12","k13":"v13"},"l1":[100]}
Advertisements