<?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: Convert JSON Object to list of Key/Value pairs in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335948#M104451</link>
    <description>&lt;P&gt;You should use the tExtractJSONFields component for this. An API will always return only the fields specified in the API documentation. It won't necessarily return each of them each time, but it won't add more unless the API is changed. As such, you should set up your tExtractJSONFields component to attempt to collect every possible field that could be returned. After you have that, you can use logic within the job to get hold of the data you need.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Dec 2022 16:49:42 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-12-01T16:49:42Z</dc:date>
    <item>
      <title>Convert JSON Object to list of Key/Value pairs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335947#M104450</link>
      <description>&lt;P&gt;I'm invoking the AdobeSign REST API and retrieving a list of fields on a given agreement. &lt;/P&gt;&lt;P&gt;I'm having troubles in trying to pivot this response to a list of KV pairs (which will later be stored in a DB table with a schema like: agreementId|key|value)&lt;/P&gt;&lt;P&gt;A sample response from the API migth look like this:&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; {"Department":"IT","role":"SIGNER","last":"Doe","Username":"jdoe","agreementId":"CYJCHBEWABAA39c6RGZvWjU_THltN_TfFGKBM2swbyD2","company":"CompanyA.","USER ID":"8100012345","completed":"2022-11-21 07:59:18","title":"","email":"jdoe@email.com","first":"John"}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The catch, is that each API call might generate a different list of fields, so defining a fixed Schema will not work.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've thought about using a tMap - but I'm not sure how to setup the expression to have it split on the JSON object's keys. &lt;/P&gt;&lt;P&gt;I've also considered using a tJavaRow to parse the JSON object in a loop (easy enough) - but I'm missing how to convert the output to a list in tJavaRow. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;psuedo-code for tJavaRow:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;foreach(string key in JSON.parse(input_row.fields))&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;  output_row.key  = key;&lt;/P&gt;&lt;P&gt;  output_row.value = input_row.fields.key&lt;/P&gt;&lt;P&gt;  output_row.agreementId = &lt;/P&gt;&lt;P&gt;(String)globalMap.get("AgreementId");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000aDVWrAAO.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/145182i63A04286B42D2F9D/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000aDVWrAAO.png" alt="0695b00000aDVWrAAO.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;any help or guidance on handling non-fixed schemas would be helpful. &lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 22:18:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335947#M104450</guid>
      <dc:creator>ksudm</dc:creator>
      <dc:date>2024-11-15T22:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON Object to list of Key/Value pairs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335948#M104451</link>
      <description>&lt;P&gt;You should use the tExtractJSONFields component for this. An API will always return only the fields specified in the API documentation. It won't necessarily return each of them each time, but it won't add more unless the API is changed. As such, you should set up your tExtractJSONFields component to attempt to collect every possible field that could be returned. After you have that, you can use logic within the job to get hold of the data you need.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 16:49:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335948#M104451</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-12-01T16:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON Object to list of Key/Value pairs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335949#M104452</link>
      <description>&lt;P&gt;Thanks for the reply - I left out the parent node in this JSON response (thinking it wasn't relevant). &lt;/P&gt;&lt;P&gt;The full JSON response from tRESTclient looks like this:&lt;/P&gt;&lt;P&gt;{"formDataList":{"fieldA": "foo", "fieldB":"bar" .... }}&lt;/P&gt;&lt;P&gt;and another call (using a different agreementId to the API)&lt;/P&gt;&lt;P&gt;{"formDataList":{"fieldC": "morefoo", "fieldD":"morebar" .... }}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The items under formDataList are unique to each invocation of the API. The only schema element that will be expected will be  "formDataList"  at the root. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 18:13:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335949#M104452</guid>
      <dc:creator>ksudm</dc:creator>
      <dc:date>2022-12-02T18:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON Object to list of Key/Value pairs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335950#M104453</link>
      <description>&lt;P&gt;FYI - I'm going to test your post on another thread to see if a tJavaFlex component might help&lt;/P&gt;&lt;P&gt;https://community.talend.com/s/question/0D55b000086tBowCAE/how-to-process-anonymous-json-for-key-value-pairs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 18:14:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335950#M104453</guid>
      <dc:creator>ksudm</dc:creator>
      <dc:date>2022-12-02T18:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON Object to list of Key/Value pairs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335951#M104454</link>
      <description>&lt;P&gt;OK. I may have misunderstood your request a little here. The other solution I provided may work for you. It does seem a bit strange that an API would return fields which are not pre-identified. But hey, it is possible I guess. Just not ideal.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 18:24:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335951#M104454</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-12-02T18:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON Object to list of Key/Value pairs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335952#M104455</link>
      <description>&lt;P&gt;Thanks it looks like that did the trick. &lt;/P&gt;&lt;P&gt;For context, this API returns back custom attributes from an AdobeSign agreement. Each agreement (of type of agreements) will have their own form fields...hence why these would be different. &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000aE1zHAAS.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/155720iD1500EE061A5083D/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000aE1zHAAS.png" alt="0695b00000aE1zHAAS.png" /&gt;&lt;/span&gt;The top row is a check for a BearerToken needed for tRestClient. &lt;/P&gt;&lt;P&gt;After tRESTClient, tExtractJSONFields_1 pulls out "formDataList" and stashes that string into a globalMap var (the data is a single string...otherwise might use tBufferOutput?). &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found that if I didn't put tJavaFlex in its own subJob, the JSON results from tRestClient wouldn't be available to the Start of tJavaFlex (same applies to tJava). &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then tJavaFlex can start off with:&lt;/P&gt;&lt;P&gt;`JSONObject obj = new JSONObject((String)globalMap.get("jsonFields"));`&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 19:03:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335952#M104455</guid>
      <dc:creator>ksudm</dc:creator>
      <dc:date>2022-12-02T19:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON Object to list of Key/Value pairs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335953#M104456</link>
      <description>&lt;P&gt;Glad it works! This one of the key benefits of Talend that brought me to spend a big chunk of my career working with it and now working for Talend. The ability to enhance what comes out of the box with a bit of Java, is SO powerful.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 19:19:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Convert-JSON-Object-to-list-of-Key-Value-pairs/m-p/2335953#M104456</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-12-02T19:19:20Z</dc:date>
    </item>
  </channel>
</rss>

