-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonDemo.java
More file actions
24 lines (20 loc) · 728 Bytes
/
JsonDemo.java
File metadata and controls
24 lines (20 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package jdk.sandbox.demo;
import jdk.sandbox.java.util.json.Json;
import jdk.sandbox.java.util.json.JsonObject;
import jdk.sandbox.java.util.json.JsonString;
import jdk.sandbox.java.util.json.JsonNumber;
import java.util.Map;
public class JsonDemo {
public static void main(String[] args) {
// Create a JSON object using the factory method
JsonObject jsonObject = JsonObject.of(Map.of(
"name", JsonString.of("John"),
"age", JsonNumber.of(30)
));
System.out.println(jsonObject);
// Parse JSON string
String jsonStr = "{\"name\":\"Jane\",\"age\":25}";
var parsed = Json.parse(jsonStr);
System.out.println("Parsed: " + parsed);
}
}