Answers for "print json object"

0

js print object as json

var obj = {
  a: 1,
  b: 2,
  c: { d: 3, e: 4 } // object in object
};

// method 1 - simple output
console.log(JSON.stringify(obj)); // {"a":1,"b":2,"c":{"d":3,"e":4}}

// method 2 - more readable output
console.log(JSON.stringify(obj, null, 2)); // 2 - indent spaces. Output below
/*
{
  "a": 1,
  "b": 2,
  "c": {
    "d": 3,
    "e": 4
  }
}
*/
Posted by: Guest on October-30-2020
0

print json object

ObjectMapper mapper = new ObjectMapper();
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject))
Posted by: Guest on July-06-2021
0

print json

ObjectMapper mapper = new ObjectMapper();
String perttyStr = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
Posted by: Guest on September-27-2021

Browse Popular Code Answers by Language