SlideShare a Scribd company logo
JSON ALAPOK
{
  "name": "John Doe",
  "age": 29,
  "siblings": ["Jane Doe", "Herry Doe"],
  "address": {
    "city": "Budapest",
    "street": "Deak Square"
  },
  "alive": false,
  "description": null
}
{
  "name": "John Doe", // <­ String
  "age": 29, // <­ Number
  "siblings": ["Jane Doe", "Herry Doe"], // <­ Array
  "address": {
      "city": "Budapest",
      "street": "Deak Square"
  }, // <­ Object
  "alive": false, // <­ true/false
  "description": null // <­ null
}
PROGRAMMING MODELS
object model
streaming model
PACKAGE: JAVAX.JSON
reader interface
writer interface
model builder interface
PACKAGE: JAVAX.JSON.STREAM
parser interface
generator interface
LET'S CODE
Docs:
https://docs.oracle.com/javaee/7/api/javax/json/package-
summary.html
EXERCISE 1:
Olvassunk be json modelt stringből Használjunk hozzá
StringReader-t és JsonReader-t
Fordításhoz használjuk a Glassfish implementációt:
org.glassfish; javax.json; 1.0.4
http://mvnrepository.com/artifact/org.glassfish/javax.json/1.0.4
<!­­?xml version="1.0" encoding="UTF­8"?­­>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.
  <modelversion>4.0.0</modelversion>
  <groupid>hu.huog.jsonp</groupid>
  <artifactid>exercises</artifactid>
  <version>1.0­SNAPSHOT</version>
  <packaging>jar</packaging>
  <build>
      <plugins>
          <plugin>
              <groupid>org.apache.maven.plugins</groupid>
              <artifactid>maven­jar­plugin</artifactid>
              <configuration>
                  <archive>
                      <manifest>
                          <mainclass>Exercise00</mainclass>
                          <addclasspath>true</addclasspath>
                      </manifest>
                  </archive>
              </configuration>
          </plugin>
      </plugins>
  </build>
  <dependencies>
      <dependency>
          <groupid>org.glassfish</groupid>
          <artifactid>javax.json</artifactid>
          <version>1.0.4</version>
      </dependency>
  </dependencies>
</project>
          
import javax.json.Json;
import javax.json.JsonReader;
import javax.json.JsonStructure;
import java.io.StringReader;
public class Exercise01 {
    private static final String jsonString = "{ "name": "John Snow"}"
    public static void main(String[] args) {
        JsonReader reader = Json.createReader(new StringReader(jsonString));
        JsonStructure jsonst = reader.read();
        reader.close();
        System.out.println("json: " + jsonst);
    }
}
          
EXERCISE 2:
Készítsünk json modelt builder segítségével és írjuk ki
stringbe Használjunk JsonObjectBuilder-t,
JsonArrayBuilder-t, JsonWriter-t, StringWriter-t
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonWriter;
import java.io.StringWriter;
public class Exercise01 {
    public static void main(String[] args) {
        JsonObject model = Json.createObjectBuilder()
            .add("firstName", "Duke")
            .add("lastName", "Java")
            .add("age", 18)
            .add("streetAddress", "100 Internet Dr")
            .add("city", "JavaTown")
            .add("state", "JA")
            .add("postalCode", "12345")
            .add("phoneNumbers", Json.createArrayBuilder()
            .add(Json.createObjectBuilder()
            .add("type", "mobile")
            .add("number", "111­111­1111"))
            .add(Json.createObjectBuilder()
            .add("type", "home")
            .add("number", "222­222­2222")))
            .build();
        StringWriter strWriter = new StringWriter();
        JsonWriter jsonWriter = Json.createWriter(strWriter);
        jsonWriter.writeObject(model);
        jsonWriter.close();
        String jsonStr = strWriter.toString();
        System.out.println("json: " + jsonStr);
    }
}
          
EXERCISE 3:
Parsoljunk json stringet és irassuk ki a parse eventeket
Használjunk JsonParser-t
import javax.json.Json;
import javax.json.stream.JsonParser;
import java.io.StringReader;
public class Exercise03 {
    private static final String jsonString = "{ "name": "John Snow"}"
    public static void main(String[] args) {
        JsonParser parser = Json.createParser(new StringReader(jsonString));
        while (parser.hasNext()) {
            JsonParser.Event event = parser.next();
            switch(event) {
                case START_ARRAY:
                case END_ARRAY:
                case START_OBJECT:
                case END_OBJECT:
                case VALUE_FALSE:
                case VALUE_NULL:
                case VALUE_TRUE:
                    System.out.println(event.toString());
                    break;
                case KEY_NAME:
                    System.out.print(event.toString() + " " +
                    parser.getString() + " ­ ");
                    break;
                case VALUE_STRING:
                case VALUE_NUMBER:
                    System.out.println(event.toString() + " " +
                    parser.getString());
                    break;
            }
        }
    }
}
          
EXERCISE 4:
Készítsünk JSON stringet geerátor segítségével Használjunk
JsonGenerator-t, StringWriter-t
import javax.json.Json;
import javax.json.stream.JsonGenerator;
import java.io.StringWriter;
public class Exercise04 {
    public static void main(String[] args) {
        StringWriter writer = new StringWriter();
        JsonGenerator gen = Json.createGenerator(writer);
        gen.writeStartObject()
            .write("firstName", "Duke")
            .write("lastName", "Java")
            .write("age", 18)
            .write("streetAddress", "100 Internet Dr")
            .write("city", "JavaTown")
            .write("state", "JA")
            .write("postalCode", "12345")
            .writeStartArray("phoneNumbers")
            .writeStartObject()
            .write("type", "mobile")
            .write("number", "111­111­1111")
            .writeEnd()
            .writeStartObject()
            .write("type", "home")
            .write("number", "222­222­2222")
            .writeEnd()
            .writeEnd()
            .writeEnd();
        gen.close();
        String jsonString = writer.toString();
        System.out.println("json:" + jsonString);
    }
}
          
JSR374 (JSON PROCESSING 1.1)
wget http://download.oracle.com/otn-pub/jcp/json_p-
1_1-edr-spec/jsonp-1.1-edr1-sources.zip
wget http://download.oracle.com/otn-pub/jcp/json_p-
1_1-edr-spec/jsonp-1.1-edr1-javadoc.zip
http://download.oracle.com/otndocs/jcp/json_p-1_1-edr-
spec/index.html
RESOURCES:
https://docs.oracle.com/javaee/7/api/javax/json/package-
summary.html
https://docs.oracle.com/javaee/7/tutorial/jsonp.htm
http://www.jcp.org/en/jsr/detail?id=353
http://www.jcp.org/en/jsr/detail?id=374
https://github.com/google/gson
https://github.com/FasterXML/jackson

More Related Content

Recently uploaded (20)

PPTX
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PPTX
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
 
PDF
Ready Layer One: Intro to the Model Context Protocol
mmckenna1
 
PDF
Dipole Tech Innovations – Global IT Solutions for Business Growth
dipoletechi3
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PPTX
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Latest Capcut Pro 5.9.0 Crack Version For PC {Fully 2025
utfefguu
 
PPTX
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
PPTX
BB FlashBack Pro 5.61.0.4843 With Crack Free Download
cracked shares
 
PPTX
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
UI5con_2025_Accessibility_Ever_Evolving_
gerganakremenska1
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
Is Framer the Future of AI Powered No-Code Development?
Isla Pandora
 
PDF
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
 
Ready Layer One: Intro to the Model Context Protocol
mmckenna1
 
Dipole Tech Innovations – Global IT Solutions for Business Growth
dipoletechi3
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Latest Capcut Pro 5.9.0 Crack Version For PC {Fully 2025
utfefguu
 
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
BB FlashBack Pro 5.61.0.4843 With Crack Free Download
cracked shares
 
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
UI5con_2025_Accessibility_Ever_Evolving_
gerganakremenska1
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Is Framer the Future of AI Powered No-Code Development?
Isla Pandora
 
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 

Featured (20)

PDF
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
 
PDF
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
 
PDF
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
 
PDF
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
 
PDF
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
PDF
Everything You Need To Know About ChatGPT
Expeed Software
 
PDF
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
PDF
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
PDF
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
PDF
Skeleton Culture Code
Skeleton Technologies
 
PDF
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
PDF
Content Methodology: A Best Practices Report (Webinar)
contently
 
PPTX
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
PDF
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
PDF
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
PDF
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
PDF
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
PDF
Getting into the tech field. what next
Tessa Mero
 
PDF
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
PDF
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
 
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
 
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
 
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
 
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Ad

Jsonp coding dojo