<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need help using tExtractJSONFields to parse JSON input in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Need-help-using-tExtractJSONFields-to-parse-JSON-input/m-p/2199895#M2620</link>
    <description>&lt;P&gt;You can use JSON API library for this - java-son-api-1.0.jar&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-05-19 at 6.45.26 AM.png" style="width: 400px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009LuSd.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/155581i614352F98DC054A4/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009LuSd.png" alt="0683p000009LuSd.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;tJavaFlex code:&lt;/P&gt; 
&lt;PRE&gt;JSONObject object = new JSONObject(row4.line);
String[] keys = JSONObject.getNames(object);

for (String key : keys)
{
    Object value = object.get(key);
}

globalMap.put("array_size", keys.length);

List keylist = Arrays.asList(keys);
globalMap.put("vk",keylist);&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;in advanced tab:&lt;/P&gt; 
&lt;PRE&gt;import org.json.*;
import java.util.*;&lt;/PRE&gt; 
&lt;P&gt;than in next tJavaFlex - select next KEY for JSON parse:&lt;/P&gt; 
&lt;PRE&gt;//System.out.println(globalMap.get("vk"));

List&amp;lt;String&amp;gt; alist = (List&amp;lt;String&amp;gt;)globalMap.get("vk");

Integer ii = ((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))-1;

//row18.jkeys=alist.get(ii);
globalMap.put("jkey",alist.get(ii));&lt;/PRE&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-05-19 at 6.50.04 AM.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009LuJU.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/146732i5E4941E3C1C9A036/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009LuJU.png" alt="0683p000009LuJU.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 18 May 2017 19:51:24 GMT</pubDate>
    <dc:creator>vapukov</dc:creator>
    <dc:date>2017-05-18T19:51:24Z</dc:date>
    <item>
      <title>Need help using tExtractJSONFields to parse JSON input</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Need-help-using-tExtractJSONFields-to-parse-JSON-input/m-p/2199894#M2619</link>
      <description>&lt;P&gt;Hello Talend Community!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm having trouble parsing a JSON file that is formatted as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;{
  "meta": {
    "dates": [
      "2017-01-01",
      "2017-01-02"
    ]
  },
  "data": {
    "2017-01-01": {
      "steps": [
        {
          "count": 14730,
          "step_conv_ratio": 1,
          "goal": "Annubis-land",
          "overall_conv_ratio": 1,
          "avg_time": null,
          "event": "Annubis-land"
        },
        {
          "count": 6999,
          "step_conv_ratio": 0.475152749490835,
          "goal": "Annubis-go",
          "overall_conv_ratio": 0.475152749490835,
          "avg_time": 323,
          "event": "Annubis-go"
        },
        {
          "count": 933,
          "step_conv_ratio": 0.13330475782254608,
          "goal": "PA-formgen-success",
          "overall_conv_ratio": 0.06334012219959267,
          "avg_time": 407,
          "event": "PA-formgen-success"
        }
      ],
      "analysis": {
        "completion": 933,
        "starting_amount": 14730,
        "steps": 3,
        "worst": 2
      }
    },
    "2017-01-02": {
      "steps": [
        {
          "count": 31111,
          "step_conv_ratio": 1,
          "goal": "Annubis-land",
          "overall_conv_ratio": 1,
          "avg_time": null,
          "event": "Annubis-land"
        },
        {
          "count": 16219,
          "step_conv_ratio": 0.5213268618816496,
          "goal": "Annubis-go",
          "overall_conv_ratio": 0.5213268618816496,
          "avg_time": 201,
          "event": "Annubis-go"
        },
        {
          "count": 2181,
          "step_conv_ratio": 0.1344719156544793,
          "goal": "PA-formgen-success",
          "overall_conv_ratio": 0.07010382179936357,
          "avg_time": 554,
          "event": "PA-formgen-success"
        }
      ],
      "analysis": {
        "completion": 2181,
        "starting_amount": 31111,
        "steps": 3,
        "worst": 2
      }
    }
  }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm interested in parsing everything contained in the "data" key, and I need to loop over each date and then each step to get: date - step -&amp;nbsp;count -&amp;nbsp;step_conv_ratio - etc...&lt;/P&gt;
&lt;P&gt;The problem is that the dates are key names, and I don't know how to get this to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could someone here help me or tell me if this is doable using JsonPath or Xpath?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried a workaround by dealing with the whole file in a routine, by using a JSON parser but I can't neither get this to work (can't load the correct library for JSON parsing). Anyway let's try to solve the problme with the tExtractJSONFields component first!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thx!&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 16:06:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Need-help-using-tExtractJSONFields-to-parse-JSON-input/m-p/2199894#M2619</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-05-18T16:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using tExtractJSONFields to parse JSON input</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Need-help-using-tExtractJSONFields-to-parse-JSON-input/m-p/2199895#M2620</link>
      <description>&lt;P&gt;You can use JSON API library for this - java-son-api-1.0.jar&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-05-19 at 6.45.26 AM.png" style="width: 400px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009LuSd.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/155581i614352F98DC054A4/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009LuSd.png" alt="0683p000009LuSd.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;tJavaFlex code:&lt;/P&gt; 
&lt;PRE&gt;JSONObject object = new JSONObject(row4.line);
String[] keys = JSONObject.getNames(object);

for (String key : keys)
{
    Object value = object.get(key);
}

globalMap.put("array_size", keys.length);

List keylist = Arrays.asList(keys);
globalMap.put("vk",keylist);&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;in advanced tab:&lt;/P&gt; 
&lt;PRE&gt;import org.json.*;
import java.util.*;&lt;/PRE&gt; 
&lt;P&gt;than in next tJavaFlex - select next KEY for JSON parse:&lt;/P&gt; 
&lt;PRE&gt;//System.out.println(globalMap.get("vk"));

List&amp;lt;String&amp;gt; alist = (List&amp;lt;String&amp;gt;)globalMap.get("vk");

Integer ii = ((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))-1;

//row18.jkeys=alist.get(ii);
globalMap.put("jkey",alist.get(ii));&lt;/PRE&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-05-19 at 6.50.04 AM.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009LuJU.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/146732i5E4941E3C1C9A036/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009LuJU.png" alt="0683p000009LuJU.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 19:51:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Need-help-using-tExtractJSONFields-to-parse-JSON-input/m-p/2199895#M2620</guid>
      <dc:creator>vapukov</dc:creator>
      <dc:date>2017-05-18T19:51:24Z</dc:date>
    </item>
  </channel>
</rss>

