{"id":8487,"date":"2014-01-24T15:45:52","date_gmt":"2014-01-24T13:45:52","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=8487"},"modified":"2021-09-24T13:21:04","modified_gmt":"2021-09-24T10:21:04","slug":"java-json-parser-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/","title":{"rendered":"Java JSON parser Example"},"content":{"rendered":"<p>In this post, we feature a comprehensive Java JSON parser Example. <code>JSON<\/code> is simply a text format that facilitates reading and writing. It is a widely used data-interchange language because of its parsing and its generation is easy for machines. In Java language, there are many ways for <code>JSON<\/code> processing.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-1-json-parsers\">1. JSON Parsers<\/h2>\n<p>In this section, we will see four different parsers for <code>JSON<\/code> available in the Java ecosystem.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-1-1-simple-json-parser\">1.1. Simple JSON parser<\/h3>\n<p>In this section we are going to use a common Java toolkit for <code>JSON<\/code> &#8211; <a rel=\"noreferrer noopener\" href=\"https:\/\/code.google.com\/p\/json-simple\/\" target=\"_blank\"><code>JSON.simple<\/code><\/a>. Before start coding we have to set a proper environment for the compiler to recognize the <code>JSON's<\/code> classes. If you want to build your project via Maven, you should add the following dependency to your <code>pom.xml<\/code>:<\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;dependency&gt;\n    &lt;groupId&gt;com.googlecode.json-simple&lt;\/groupId&gt;\n    &lt;artifactId&gt;json-simple&lt;\/artifactId&gt;\n    &lt;version&gt;1.1&lt;\/version&gt;\n&lt;\/dependency&gt;\n<\/pre>\n<p>As we mentioned, we will show how we can parse a JSON file, so we will make our own <code>.json<\/code> file. The file should be placed in <code>src\/main\/resources<\/code> directory. This file is named <code>jsonTestFile.json<\/code> and has the following structure:<\/p>\n<p><span style=\"text-decoration: underline\"><em>jsonTestFile.json<\/em><\/span><\/p>\n<pre class=\"brush:json\">{\n  \"id\": 1,\n  \"firstname\": \"Katerina\",\n  \"languages\": [\n    {\n      \"lang\": \"en\",\n      \"knowledge\": \"proficient\"\n    },\n    {\n      \"lang\": \"fr\",\n      \"knowledge\": \"advanced\"\n    }\n  ],\n  \"job\": {\n    \"site\": \"www.javacodegeeks.com\",\n    \"name\": \"Java Code Geeks\"\n  }\n}\n<\/pre>\n<p>Now create a java file in your project, named <code>JsonParseTest<\/code>. Then paste the following code.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JsonParseTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.javabasics.jsonparsertest;\n \nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.util.Iterator;\n \nimport org.json.simple.JSONArray;\nimport org.json.simple.JSONObject;\nimport org.json.simple.parser.JSONParser;\nimport org.json.simple.parser.ParseException;\n \npublic class JsonParseTest {\n \n    private static final String filePath = \"jsonTestFile.json\";\n\n    public static void main(String[] args) {\n\n        try (FileReader reader = new FileReader(ClassLoader.getSystemResource(filePath).getFile())) {\n            \/\/ read the json file\n\n\n            JSONParser jsonParser = new JSONParser();\n            JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);\n\n            \/\/ get a String from the JSON object\n            String firstName = (String) jsonObject.get(\"firstname\");\n            System.out.println(\"The first name is: \" + firstName);\n\n            \/\/ get a number from the JSON object\n            long id = (long) jsonObject.get(\"id\");\n            System.out.println(\"The id is: \" + id);\n\n            \/\/ get an array from the JSON object\n            JSONArray lang = (JSONArray) jsonObject.get(\"languages\");\n\n            \/\/ take the elements of the json array\n            for (int i = 0; i &lt; lang.size(); i++) {\n                System.out.println(\"The \" + i + \" element of the array: \" + lang.get(i));\n            }\n            Iterator i = lang.iterator();\n\n            \/\/ take each value from the json array separately\n            while (i.hasNext()) {\n                JSONObject innerObj = (JSONObject) i.next();\n                System.out.println(\"language \" + innerObj.get(\"lang\") +\n                        \" with level \" + innerObj.get(\"knowledge\"));\n            }\n            \/\/ handle a structure into the json object\n            JSONObject structure = (JSONObject) jsonObject.get(\"job\");\n            System.out.println(\"Into job structure, name: \" + structure.get(\"name\"));\n\n        } catch (Exception ex) {\n            ex.printStackTrace();\n        }\n    }\n \n}\n<\/pre>\n<p>Now let&#8217;s explain the code above. After we create an instance of <code>JSONParser<\/code>, we create a <code>JSONObject<\/code> by parsing the <code>FileReader<\/code> of our <code>.json<\/code> file. This <code>JSONObject<\/code> contains a collection of key-value pairs, from which we can get every value of the JSON file. To retrieve primitive objects, <code>get()<\/code> method of the <code>JSONObject's<\/code> instance is called, defining the specified key as an argument. It is important to add the suitable cast to the method. For array types in JSON file, <code>JSONArray<\/code> is used that represents an ordered sequence of values. As you can notice in the code, an <code>Iterator<\/code> should be used in order to take each value of the JSON array. A structure in the JSON file, signs the creation of a new <code>JSONObject<\/code> in order to retrieve the values.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>You can see the output of the execution below.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\">The first name is: Katerina\nThe id is: 1\nThe 0 element of the array: {\"knowledge\":\"proficient\",\"lang\":\"en\"}\nThe 1 element of the array: {\"knowledge\":\"advanced\",\"lang\":\"fr\"}\nlanguage en with level proficient\nlanguage fr with level advanced\nInto job structure, name: Java Code Geeks\n<\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-1-2-gson-parser\">1.2. GSON parser<\/h3>\n<p>In this section, We will cover the <code>Gson<\/code> library to convert JSON to object and vice versa. Gson can work with arbitrary Java objects including preexisting objects. It also supports the use of Java Generics. <\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;dependency&gt;\n    &lt;groupId&gt;com.google.code.gson&lt;\/groupId&gt;\n    &lt;artifactId&gt;gson&lt;\/artifactId&gt;\n    &lt;version&gt;2.8.6&lt;\/version&gt;\n&lt;\/dependency&gt;\n<\/pre>\n<p>This adds the <code>Gson<\/code> dependency to our project so that we can use it deserialize the JSON into java object.<\/p>\n<p><span style=\"text-decoration: underline\"><em>GsonParseTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">public class GsonParseTest {\n\n    private static final String filePath = \"jsonTestFile.json\";\n\n    public static void main(String[] args) {\n        Gson gson = new Gson();\n        try (FileReader reader = new FileReader(ClassLoader.getSystemResource(filePath).getFile())) {\n            Person person = gson.fromJson(reader, Person.class);\n            System.out.println(person.toString());\n       } catch (Exception ex) {\n            ex.printStackTrace();\n       }\n   }\n}<\/pre>\n<ul class=\"wp-block-list\">\n<li>The first step similar to the above is creating a reader to read the contents of JSON file.<\/li>\n<li>We construct and instance of the <code>Gson<\/code> class.<\/li>\n<li>We pass the reader to the <code>fromJson<\/code> method and provide the class to which it needs to be deserialized.<\/li>\n<li>This simple mapping is enough for <code>Gson<\/code> to deserialize the JSON into <code>Person<\/code> class.<\/li>\n<li>We use the <code>toString<\/code> method to print out the contents of the <code>Person<\/code> class.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\" id=\"h-1-3-jackson-parser\">1.3. Jackson parser<\/h3>\n<p>In this section, We will cover the <code>Jackson<\/code> library to convert JSON to object. Jackson supports data binding for various formats, but we will cover here for JSON data binding.<\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;dependency&gt;\n    &lt;groupId&gt;com.fasterxml.jackson.core&lt;\/groupId&gt;\n    &lt;artifactId&gt;jackson-databind&lt;\/artifactId&gt;\n    &lt;version&gt;2.9.6&lt;\/version&gt;\n&lt;\/dependency&gt;\n<\/pre>\n<p>This adds the <code>jackson-databing<\/code> dependency to our project so that we can use it deserialize the JSON into java object.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JacksonParseTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">public class JacksonParseTest {\n\n    private static final String filePath = \"jsonTestFile.json\";\n\n    public static void main(String[] args) {\n        ObjectMapper mapper = new ObjectMapper();\n        try (FileReader reader = new FileReader(ClassLoader.getSystemResource(filePath).getFile())) {\n            Person person = mapper.readValue(reader, Person.class);\n            System.out.println(person.toString());\n        } catch (Exception ex) {\n            ex.printStackTrace();\n        }\n   }\n}<\/pre>\n<ul class=\"wp-block-list\">\n<li>The first step similar to the above is creating a reader to read the contents of JSON file.<\/li>\n<li>We construct and instance of the <code>ObjectMapper<\/code> class.<\/li>\n<li>We pass the reader to the <code>readValue<\/code> method and provide the class to which it needs to be deserialized.<\/li>\n<li>This mapping is enough for <code>Jackson<\/code> to deserialize the JSON into <code>Person<\/code> class.<\/li>\n<li>We use the <code>toString<\/code> method to print out the contents of the <code>Person<\/code> class.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\" id=\"h-1-4-json-java\">1.4. JSON-Java<\/h3>\n<p>In this section, We will cover the <code>stleary\/JSON-java<\/code> library to convert JSON to object. It is a reference implementation for converting JSON to java object and vice versa.<\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;dependency&gt;\n    &lt;groupId&gt;org.json&lt;\/groupId&gt;\n    &lt;artifactId&gt;json&lt;\/artifactId&gt;\n    &lt;version&gt;20190722&lt;\/version&gt;\n&lt;\/dependency&gt;\n<\/pre>\n<p>This adds the <code>org.json.json<\/code> dependency to our project so that we can use it deserialize the JSON into java object.<\/p>\n<p><span style=\"text-decoration: underline\"><em>StealryJsonTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">public class StealryJsonTest {\n    private static final String filePath = \"jsonTestFile.json\";\n\n    public static void main(String[] args) {\n        try (FileReader reader = new FileReader(ClassLoader.getSystemResource(filePath).getFile())) {\n            JSONTokener tokener = new JSONTokener(reader);\n            JSONObject object = new JSONObject(tokener);\n\n            String firstName = (String) object.get(\"firstname\");\n            System.out.println(\"The first name is: \" + firstName);\n\n            \/\/ get a number from the JSON object\n            int id = (int) object.get(\"id\");\n            System.out.println(\"The id is: \" + id);\n\n            \/\/ get an array from the JSON object\n            JSONArray lang = (JSONArray) object.get(\"languages\");\n\n            \/\/ take the elements of the json array\n            for (int i = 0; i &lt; lang.length(); i++) {\n                System.out.println(\"The \" + i + \" element of the array: \" + lang.get(i));\n            }\n            Iterator i = lang.iterator();\n\n            \/\/ take each value from the json array separately\n            while (i.hasNext()) {\n                JSONObject innerObj = (JSONObject) i.next();\n                System.out.println(\"language \" + innerObj.get(\"lang\") +\n                        \" with level \" + innerObj.get(\"knowledge\"));\n            }\n            \/\/ handle a structure into the json object\n            JSONObject structure = (JSONObject) object.get(\"job\");\n            System.out.println(\"Into job structure, name: \" + structure.get(\"name\"));\n\n        } catch (Exception ex) {\n            ex.printStackTrace();\n        }\n    }\n}<\/pre>\n<ul class=\"wp-block-list\">\n<li>After we create an instance of <code>JSONTokener<\/code>, we create a <code>JSONObject<\/code> by parsing the <code>FileReader<\/code> of our <code>.json<\/code> file. <\/li>\n<li><code>JSONTokener<\/code> is used to tokenize and split the JSON string and is passed to the <code>JSONObject<\/code> for extracting the values.<\/li>\n<li>This <code>JSONObject<\/code> contains a collection of key-value pairs, from which we can get every value of the JSON file. <\/li>\n<li>To retrieve primitive objects, <code>get()<\/code> method of the <code>JSONObject's<\/code> instance is called, defining the specified key as an argument. <\/li>\n<li>For array types in JSON file, <code>JSONArray<\/code> is used that represents an ordered sequence of values. <\/li>\n<li>A structure in the JSON file, signs the creation of a new <code>JSONObject<\/code> in order to retrieve the values.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\" id=\"h-1-5-no-one-size-fits-all\">1.5. No One-size Fits All<\/h3>\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/code.google.com\/p\/json-simple\/\" target=\"_blank\"><code>JSON.simple<\/code><\/a> is good for very simple use cases while <code>stleary\/JSON-java<\/code> is more of a reference implementation. Both <code>Gson<\/code> and <code>Jackson<\/code> are good candidates for complex use cases. Jackson has the following advantages<\/p>\n<ul class=\"wp-block-list\">\n<li> Built into all JAX-RS (Jersey, Apache CXF, RESTEasy, Restlet), and Spring framework<\/li>\n<li>Has Extensive annotation support <\/li>\n<\/ul>\n<p><code>Gson<\/code> has the following advantages <\/p>\n<ul class=\"wp-block-list\">\n<li>Can be used in third party code without annotations.<\/li>\n<li>Convenient <code>toJson<\/code> and <code>fromJson<\/code> for simplistic use-cases.<\/li>\n<\/ul>\n<p>The differences between <code>Gson<\/code> and <code>Jackson<\/code> even in the simple example. We can change the <code>firstname<\/code> property of <code>Person<\/code> class to <code>firstName<\/code>. Now if we run the previous examples <\/p>\n<p><span style=\"text-decoration: underline\"><em>Jackson<\/em><\/span><\/p>\n<pre class=\"brush:bash\">com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field \"firstname\" (class com.jcg.jsonParser.Person), not marked as ignorable (4 known properties: \"id\", \"job\", \"firstName\", \"languages\"])\n at [Source: (FileReader); line: 3, column: 17] (through reference chain: com.jcg.jsonParser.Person[\"firstname\"])\n\tat com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:60)\n\tat com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:822)\n\tat com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1152)\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1589)\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1567)\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:294)\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)\n\tat com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)\n\tat com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3049)\n\tat com.jcg.jsonParser.JacksonParseTest.main(JacksonParseTest.java:13)\n<\/pre>\n<p>We get an error as <code>Jackson<\/code> is unable to deserialize the property <code>firstname<\/code> and it is not marked as <code>ignorable<\/code>. Running the same example in <code>Gson<\/code>, we get the below output<\/p>\n<p><span style=\"text-decoration: underline\"><em>Gson<\/em><\/span><\/p>\n<pre class=\"brush:bash\">Person{id='1', firstName='null', languages=[Language{lang='en', knowledge='proficient'}, Language{lang='fr', knowledge='advanced'}], job=Job{site='www.javacodegeeks.com', name='Java Code Geeks'}}\n<\/pre>\n<p>Here, it fails softly by setting the <code>firstName<\/code> field to null rather than throwing an exception as in case of <code>Jackson<\/code>.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-2-download-the-source-code\"> 2. Download the Source Code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nDownload the source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/10\/JSONParsers.zip\"><strong>Java JSON parser Example<\/strong><\/a><\/div>\n<p><strong>Last updated on Oct. 07, 2019<\/strong><\/p>\n<p><b>Don&#8217;t forget to check out our <a href=\"http:\/\/academy.javacodegeeks.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Academy premium site<\/a> for advanced Java training!<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, we feature a comprehensive Java JSON parser Example. JSON is simply a text format that facilitates reading and writing. It is a widely used data-interchange language because of its parsing and its generation is easy for machines. In Java language, there are many ways for JSON processing. 1. JSON Parsers In this &hellip;<\/p>\n","protected":false},"author":11,"featured_media":1211,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[549],"class_list":["post-8487","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-json","tag-json-simple-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java JSON parser Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Check out our detailed Java JSON parser Example! We are going to use a common Java toolkit for JSON - JSON.simple.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java JSON parser Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Check out our detailed Java JSON parser Example! We are going to use a common Java toolkit for JSON - JSON.simple.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-01-24T13:45:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-24T10:21:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Katerina Zamani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Katerina Zamani\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/\"},\"author\":{\"name\":\"Katerina Zamani\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673\"},\"headline\":\"Java JSON parser Example\",\"datePublished\":\"2014-01-24T13:45:52+00:00\",\"dateModified\":\"2021-09-24T10:21:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/\"},\"wordCount\":879,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg\",\"keywords\":[\"JSON.simple\"],\"articleSection\":[\"json\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/\",\"name\":\"Java JSON parser Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg\",\"datePublished\":\"2014-01-24T13:45:52+00:00\",\"dateModified\":\"2021-09-24T10:21:04+00:00\",\"description\":\"Check out our detailed Java JSON parser Example! We are going to use a common Java toolkit for JSON - JSON.simple.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"json\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/json\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Java JSON parser Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673\",\"name\":\"Katerina Zamani\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg\",\"caption\":\"Katerina Zamani\"},\"description\":\"Katerina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she attends MSc courses in Advanced Information Systems at the same department. Currently, her main academic interests focus on web applications, mobile development, software engineering, databases and telecommunications.\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/katerina-zamani\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java JSON parser Example - Java Code Geeks","description":"Check out our detailed Java JSON parser Example! We are going to use a common Java toolkit for JSON - JSON.simple.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/","og_locale":"en_US","og_type":"article","og_title":"Java JSON parser Example - Java Code Geeks","og_description":"Check out our detailed Java JSON parser Example! We are going to use a common Java toolkit for JSON - JSON.simple.","og_url":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-01-24T13:45:52+00:00","article_modified_time":"2021-09-24T10:21:04+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg","type":"image\/jpeg"}],"author":"Katerina Zamani","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Katerina Zamani","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/"},"author":{"name":"Katerina Zamani","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673"},"headline":"Java JSON parser Example","datePublished":"2014-01-24T13:45:52+00:00","dateModified":"2021-09-24T10:21:04+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/"},"wordCount":879,"commentCount":3,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg","keywords":["JSON.simple"],"articleSection":["json"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/","name":"Java JSON parser Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg","datePublished":"2014-01-24T13:45:52+00:00","dateModified":"2021-09-24T10:21:04+00:00","description":"Check out our detailed Java JSON parser Example! We are going to use a common Java toolkit for JSON - JSON.simple.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-json-parser-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"json","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/json\/"},{"@type":"ListItem","position":5,"name":"Java JSON parser Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673","name":"Katerina Zamani","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg","caption":"Katerina Zamani"},"description":"Katerina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she attends MSc courses in Advanced Information Systems at the same department. Currently, her main academic interests focus on web applications, mobile development, software engineering, databases and telecommunications.","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/katerina-zamani\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/8487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=8487"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/8487\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1211"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=8487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=8487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=8487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}