creating json object in java

String jsonString = new JSONObject()
                  .put("JSON1", "Hello World!")
                  .put("JSON2", "Hello my World!")
                  .put("JSON3", new JSONObject().put("key1", "value1"))
                  .toString();

System.out.println(jsonString);

4
4
Phoenix Logan 186120 points

                                    import org.json.simple.JSONObject;

class JsonEncodeDemo {

   public static void main(String[] args) {
	
      JSONObject obj = new JSONObject();

      obj.put("name","foo");
      obj.put("num",new Integer(100));
      obj.put("balance",new Double(1000.21));
      obj.put("is_vip",new Boolean(true));

      StringWriter out = new StringWriter();
      obj.writeJSONString(out);
      
      String jsonText = out.toString();
      System.out.print(jsonText);
   }
}

4 (4 Votes)
0
3
1
Phoenix Logan 186120 points

                                    String json = Json.createObjectBuilder()
            .add("key1", "value1")
            .add("key2", "value2")
            .build()
            .toString();

3 (1 Votes)
0
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
json build java how to create a json in java create jsonobject java creating json object in java java make json object create a json string in java creating json in javas creating a json string java java make json item how to create json with string in java create json from object java create json to java object build json java java working create json construct a json in java creat json object injava create jsonobject from string java how to construct json object in java defining json in java how to make json java create json object from java object java jsonobject create creating json in java create json object java create json objects java java take json and create object create java object to json making json object in java create a json in java writing jsonobject in java making a json object in java create json object string java create java object from json declare json object in java declare json in java create object of json java java how to create json object create json objects in java how to create json object in java java construct a simple json object create a java object from json object how to write a json object in Java how to create new JSONObject java create a json object using java java build in json java build json how to declare a json object in java how to make json object java create an json object in java java creating json object create json object in java how create json object in java craete json object in java Java create JSON Object java json create create json onbjects in java create json with json java simple jsonobject to java object how create json in java make json object java make json objet java java jsonobject make Create JSON java creating a json in java creating json objects in java java create json string how to create json in java java create jason object Java create json create json in java create a new json object java how to n json object in java declare a json in java how to create json object from object in java create a json object in java how to create a json object in java how to create a json from java object create json object from object java
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