<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Parse complex JSON response from REST call</title><link>https://answers.axonivy.com/questions/1468/parse-complex-json-response-from-rest-call</link><description>&lt;p&gt;I use the REST api of google to trigger a search on their search engine.
This works as expected. The result of the call is a complex JSON string. &lt;/p&gt;
&lt;p&gt;See &lt;a href="http://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;amp;q=ivyTeam"&gt;http://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;amp;q=ivyTeam&lt;/a&gt;
&lt;img alt="sampleJson" src="http://answers.axonivy.com/upfiles/sampleJsonFromGoogle.PNG"&gt;&lt;/p&gt;
&lt;p&gt;How can I comfortably access this complex result in ivy. With Java or ivyScript?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1468/parse-complex-json-response-from-rest-call" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 08 Sep 2015 16:27:58 -0400</lastBuildDate><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/1468/parse-complex-json-response-from-rest-call/1469</link><description>&lt;p&gt;You can easily access the JSON response content if you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;use a java pojo generator that creates a complex java class structure out of a JSON string&lt;/li&gt;
&lt;li&gt;use &lt;a href="https://github.com/google/gson"&gt;Gson&lt;/a&gt; to parse the JSON string into instances of the generated java classes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Generate classes:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Copy the whole JSON string into your clipboard and paste it into a java generator: &lt;a href="http://www.jsonschema2pojo.org/"&gt;http://www.jsonschema2pojo.org/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Configure the generator:&lt;/li&gt;
&lt;li&gt;package = com.google.generated&lt;/li&gt;
&lt;li&gt;class = QueryResponse&lt;/li&gt;
&lt;li&gt;source type = JSON&lt;/li&gt;
&lt;li&gt;annotation style = GSON&lt;/li&gt;
&lt;li&gt;generate the java source by pressing on the "JAR" button. &lt;/li&gt;
&lt;li&gt;download the generated sources jar.&lt;/li&gt;
&lt;li&gt;copy the content of the sources-jar into your ivy projects sources folder&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Parse JSON as java objects&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;add the latest gson.jar to our classpath: download the jar -&amp;gt; switch to java perspective -&amp;gt; copy the jar into a directory of the project -&amp;gt; right click on jar -&amp;gt; build path -&amp;gt; add to build path&lt;/li&gt;
&lt;li&gt;QueryResponse response = new Gson().fromJson("{yourComplexResponse}", QueryResponse.class);&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="java pojo generator" src="http://answers.axonivy.com/upfiles/javaPojoGenerator.PNG"&gt;
&lt;img alt="json pojos in ivy project" src="http://answers.axonivy.com/upfiles/generatedPojosInIvyProject.PNG"&gt;
&lt;img alt="convert json to java" src="http://answers.axonivy.com/upfiles/jsonToGsonInIvy.PNG"&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Tue, 08 Sep 2015 16:27:58 -0400</pubDate><guid>https://answers.axonivy.com/questions/1468/parse-complex-json-response-from-rest-call/1469</guid></item></channel></rss>