
- JSON.simple Tutorial
- 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
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JSON.simple - Merging Objects
In JSON.simple, we can merge two JSON Objects easily using JSONObject.putAll() method.
Following example illustrates the above concept.
Example
import java.io.IOException; import org.json.simple.JSONObject; class JsonDemo { public static void main(String[] args) throws IOException { JSONObject obj1 = new JSONObject(); obj1.put("name", "foo"); obj1.put("num", new Integer(100)); JSONObject obj2 = new JSONObject(); obj2.put("balance", new Double(1000.21)); obj2.put("is_vip", new Boolean(true)); obj1.putAll(obj2); System.out.println(obj1); } }
Output
{"balance":1000.21,"is_vip":true,"num":100,"name":"foo"}
Advertisements