<?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: Split String into Key / Value in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320114#M90286</link>
    <description>&lt;P&gt;Maybe you have a "\r\n" instead of a "\n" in your input.&lt;/P&gt;&lt;P&gt;If it comes from a text file, this is possible.&lt;/P&gt;</description>
    <pubDate>Fri, 05 Apr 2019 12:55:17 GMT</pubDate>
    <dc:creator>TRF</dc:creator>
    <dc:date>2019-04-05T12:55:17Z</dc:date>
    <item>
      <title>Split String into Key / Value</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320109#M90281</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt; 
&lt;P&gt;I have a long string that I'd like to split into key values:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;# Key1: Value1\n# Key2: Value2\n# Key3: Value3...&lt;/PRE&gt; 
&lt;P&gt;I split the string with a tNormalize and removed the \n with a tJavaRow, but how do I get the values written as Key / Value in a JSON?&amp;nbsp;I tried before to convert the string into an array and use tMap to map part[0] and part[1] into a schema, but i can't use tMap with an array. In addition, there isn't always a key. Some points consist only of values:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;# Key3: Value3\n# Value\n# Key4: Value4\n...&lt;/PRE&gt; 
&lt;P&gt;To use Javacode to write the key/values directly into a JSON file isnt realy an option, cause the data have to combine with other data later.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;If anyone had an idea, I'd really appreciate it. I saw that there was already &lt;A href="https://community.qlik.com/s/feed/0D53p00007vCnwrCAC" target="_self"&gt;another topic here in the forum&lt;/A&gt;, but I failed a bit because of the complexity and I think it's more than I need.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Best regards&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 02:20:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320109#M90281</guid>
      <dc:creator>BooWseR</dc:creator>
      <dc:date>2019-04-05T02:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: Split String into Key / Value</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320110#M90282</link>
      <description>Can share the expected result based on your input?</description>
      <pubDate>Fri, 05 Apr 2019 07:06:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320110#M90282</guid>
      <dc:creator>TRF</dc:creator>
      <dc:date>2019-04-05T07:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: Split String into Key / Value</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320111#M90283</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thanks for the quick response.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;My final result should be like:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;PRE&gt;&amp;lt;product_description&amp;gt;
&amp;lt;key1&amp;gt;Value1&amp;lt;/key1&amp;gt;
&amp;lt;key2&amp;gt;Value2&amp;lt;/key2&amp;gt;
....
&amp;lt;/product_description&amp;gt;&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Like i said, these data are only a part of the job, so i have to write the JSON later.&amp;nbsp;For the beginning, it would be great if I could handle the data as separated as possible. If Key and Value were in separate fields, I could assign the data in tMap as I want.&lt;/DIV&gt;&lt;DIV&gt;The problem is that the final structure is not completely finished yet, but I would like to handle the data as separated as possible.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I hope you know what I mean.&lt;/DIV&gt;</description>
      <pubDate>Fri, 05 Apr 2019 07:27:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320111#M90283</guid>
      <dc:creator>BooWseR</dc:creator>
      <dc:date>2019-04-05T07:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Split String into Key / Value</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320112#M90284</link>
      <description>&lt;P&gt;Based on your sample, I used a tNormalize with "\n" for the separator:&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="img1.png" style="width: 593px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M3Lk.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/148850iAA9387E9165D3E22/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M3Lk.png" alt="0683p000009M3Lk.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;Then the magic is with the tMap wich allow to separate keys and values using an array (yes, you can):&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="img2.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M3Y9.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/150344i1330EFF9ADA6BBA0/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M3Y9.png" alt="0683p000009M3Y9.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;Here are the expressions to get the keys and values (when no key, a key name is generated).&lt;/P&gt; 
&lt;P&gt;Keys :&lt;/P&gt; 
&lt;PRE&gt;((String[])Var.var1).length &amp;gt; 1 ? ((String[])Var.var1)[0] : "newKey" + Numeric.sequence("newKey", 1, 1) &lt;/PRE&gt; 
&lt;P&gt;Values:&lt;/P&gt; 
&lt;PRE&gt;((String[])Var.var1).length &amp;gt; 1 ? ((String[])Var.var1)[1] : ((String[])Var.var1)[0] &lt;/PRE&gt; 
&lt;P&gt;And the result is:&lt;/P&gt; 
&lt;PRE&gt;[statistics] connecting to socket on port 3609
[statistics] connected
.-------+------.
|  tLogRow_10  |
|=------+-----=|
|key    |value |
|=------+-----=|
|Key1   |Value1|
|Key2   |Value2|
|Key3   |Value3|
|newKey1|Value |
|Key4   |Value4|
'-------+------'

[statistics] disconnected&lt;/PRE&gt; 
&lt;P&gt;(see the name "newKey1" when key is not in the input string).&lt;/P&gt; 
&lt;P&gt;Hope this helps.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 08:09:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320112#M90284</guid>
      <dc:creator>TRF</dc:creator>
      <dc:date>2019-04-05T08:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Split String into Key / Value</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320113#M90285</link>
      <description>&lt;P&gt;That's brilliant! Thank you very much for that.&lt;/P&gt; 
&lt;P&gt;&lt;BR /&gt;But what doesn't work for me is the tNormalize with the "\n" separator.&amp;nbsp;Here I have to split to # and then replace the \n in tMap.&amp;nbsp;It works too.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Best regards &lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MACn.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/154443iC5B8CACEF3D12C6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MACn.png" alt="0683p000009MACn.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 12:41:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320113#M90285</guid>
      <dc:creator>BooWseR</dc:creator>
      <dc:date>2019-04-05T12:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Split String into Key / Value</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320114#M90286</link>
      <description>&lt;P&gt;Maybe you have a "\r\n" instead of a "\n" in your input.&lt;/P&gt;&lt;P&gt;If it comes from a text file, this is possible.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 12:55:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320114#M90286</guid>
      <dc:creator>TRF</dc:creator>
      <dc:date>2019-04-05T12:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Split String into Key / Value</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320115#M90287</link>
      <description>&lt;P&gt;Hm.&amp;nbsp;The data comes from a JSON file. When I look in with Notepad++, I see "\\n". So yeah, maybe.&lt;/P&gt;&lt;P&gt;But another question:&amp;nbsp;In a few places I have the case that I have a key but no value.&amp;nbsp;This causes the key to be mistakenly recognized as a value.&amp;nbsp;I thought about splitting the string after ": ", because there is always a space between colon and value. If the key has no value, there is no space after the colon.&lt;/P&gt;&lt;PRE&gt;(((String[])Var.var1).length &amp;gt; 1 || ((String[])Var.var1)[0].contains(":")) ? ...&lt;/PRE&gt;&lt;P&gt;So I get the key into the key field, but I don't get it out of the value field. Any idea?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 13:46:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Split-String-into-Key-Value/m-p/2320115#M90287</guid>
      <dc:creator>BooWseR</dc:creator>
      <dc:date>2019-04-05T13:46:21Z</dc:date>
    </item>
  </channel>
</rss>

