CARVIEW |
Select Language
HTTP/2 301
server: GitHub.com
content-type: text/html
location: https://javaee.github.io/jsonp/
x-github-request-id: C942:12E98B:1011DC:129E43:68813EA6
accept-ranges: bytes
age: 0
date: Wed, 23 Jul 2025 19:57:26 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210097-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753300646.346182,VS0,VE210
vary: Accept-Encoding
x-fastly-request-id: fa7e4fe31b2ff45ebf7467fc5d83afbb70a17363
content-length: 162
HTTP/2 200
server: GitHub.com
content-type: text/html; charset=utf-8
last-modified: Sat, 27 May 2017 05:28:25 GMT
access-control-allow-origin: *
strict-transport-security: max-age=31557600
etag: W/"59290e79-303f"
expires: Wed, 23 Jul 2025 20:07:26 GMT
cache-control: max-age=600
content-encoding: gzip
x-proxy-cache: MISS
x-github-request-id: D95B:363E14:100D51:129943:68813EA6
accept-ranges: bytes
age: 0
date: Wed, 23 Jul 2025 19:57:26 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210097-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753300647.569505,VS0,VE242
vary: Accept-Encoding
x-fastly-request-id: 86b569f43be29a92903d1517936f14ebea445447
content-length: 3501
JSON Processing (JSON-P) - Home
What is JSON-P?
JSON Processing (JSON-P) is a Java API to process (for e.g. parse, generate, transform and query) JSON messages. It produces and consumes JSON text in a streaming fashion (similar to StAX API for XML) and allows to build a Java object model for JSON text using API classes (similar to DOM API for XML).
Consistent
Consistent with JAXP (Java API for XML Processing) and other Java EE and SE APIs where appropriate
Conventional
Define default mapping of Java classes and instances to JSON document counterparts
Customizable
Allow customization of the default JSON service provider
Easy to Use
Default use of the APIs should not require prior knowledge of the JSON document format and specification
To print/parse a Java Object to/from JSON
JSON-P Object Model calls
public static void main(String[] args) {
// Create Json and serialize
JsonObject json = Json.createObjectBuilder()
.add("name", "Falco")
.add("age", BigDecimal.valueOf(3))
.add("biteable", Boolean.FALSE).build();
String result = json.toString();
System.out.println(result);
}
JSON-P Streaming API calls
public static void main(String[] args) {
// Parse back
final String result = "{\"name\":\"Falco\",\"age\":3,\"bitable\":false}";
final JsonParser parser = Json.createParser(new StringReader(result));
String key = null;
String value = null;
while (parser.hasNext()) {
final Event event = parser.next();
switch (event) {
case KEY_NAME:
key = parser.getString();
System.out.println(key);
break;
case VALUE_STRING:
value = parser.getString();
System.out.println(value);
break;
}
}
parser.close();
}
The JSON representation
{
"name": "Falco",
"age": 3,
"bitable": false
}
Copyright © 2015, 2017 Oracle and/or its affiliates. All Rights Reserved.