javascript create object from json code example

Example 1: convert data into json format in javascript

Use the JavaScript function JSON.parse() to convert text into a JavaScript object:
var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');

Example 2: create a json object in javascript

var employee = {
  "firstName": firstName,
  "lastName": lastName
}

Example 3: create a javascript json object

const student = {
  name: "bob",
  age: 7,
  grade: 6
}

Example 4: convert json to object

Jackson Data-bind depdendency that take care of 
Converting between 
JSON to Java Object 
and 
Java Object to JSON

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.12.0</version>
</dependency>