Java

Create JSON data in Java

1. Download json-simple library (.jar file) from here.

2. Add a reference to the json-simple jar file.

3. Import package org.json.simple.JSONObject

4. Write your code:

JSONObject jsonobj = new JSONObject();
jsonobj.put("city", "Athens");
jsonobj.put("country", "Greece");
System.out.println(jsonobj.toString());