<?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 multiple line text into &amp;quot;JSON 1 line&amp;quot; format in Administration and Deployment</title>
    <link>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723646#M21685</link>
    <description>&lt;P&gt;Note that the 64K limit on macro variables is probably going to be less of problem than the 32K limit on character variables in SAS datasets.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Mar 2021 21:04:28 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-03-04T21:04:28Z</dc:date>
    <item>
      <title>Convert multiple line text into "JSON 1 line" format</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723472#M21678</link>
      <description>&lt;P&gt;Hello community!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have some REST API query that creates response file:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;PROC HTTP METHOD="GET" oauth_bearer=sas_services OUT=rep_id &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;URL="&lt;A href="http://pvmict002.health.fgov.be/jobDefinitions/definitions/7a0c60aa-393f-42a8-96b7-21831400f4b4" target="_blank" rel="noopener"&gt;http://pvmict002.health.fgov.be/jobDefinitions/definitions/7a0c60aa-393f-42a8-96b7-21831400f4b4&lt;/A&gt;";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;HEADERS "Accept"="application/vnd.sas.job.definition+json";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If we open the JSON response file with text editor we will see that content combined in a single line.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dandycomp_0-1614866977933.png" style="width: 670px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55437iF1CFD2D8F734FD9F/image-dimensions/670x62?v=v2" width="670" height="62" role="button" title="dandycomp_0-1614866977933.png" alt="dandycomp_0-1614866977933.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;When I try to extract this content using JSON libname, the JSON file is automatically parsed to "human readable" multiple lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;libname rep_id json;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;data code;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;set rep_id.ROOT;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;keep code;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The output table:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dandycomp_1-1614867318699.png" style="width: 255px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55438i30F4F98FD85055B2/image-dimensions/255x233?v=v2" width="255" height="233" role="button" title="dandycomp_1-1614867318699.png" alt="dandycomp_1-1614867318699.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question is:&lt;/P&gt;
&lt;P&gt;How can I convert code column(that contains multiple lines) to one-line string, the same we have in JSON file?&lt;/P&gt;
&lt;P&gt;Maybe you have other ideas how to reuse this part of the JSON file to build another input JSON file for POST request?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If possible I would like to avoid assigning the "code" parameter into macro variable to not exceed 65k characters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Ivan&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 14:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723472#M21678</guid>
      <dc:creator>idziemianczyk</dc:creator>
      <dc:date>2021-03-04T14:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: Convert multiple line text into "JSON 1 line" format</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723533#M21680</link>
      <description>&lt;P&gt;It looks like the job definition includes format characters: \n and \t. Perhaps you could remove them in your data step, maybe something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname rep_id json;
data code;
set rep_id.ROOT;
code=prxchange('s/\n\t//', -1, code);
keep code;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Mar 2021 17:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723533#M21680</guid>
      <dc:creator>gwootton</dc:creator>
      <dc:date>2021-03-04T17:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Convert multiple line text into "JSON 1 line" format</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723644#M21684</link>
      <description>&lt;P&gt;It is hard the tell from photographs of GUI screens what is actually in your data.&lt;/P&gt;
&lt;P&gt;It sounds like most likely the JSON engine has converted the "\n" in the source string into the actual new line characters.&amp;nbsp; The values are still in one variable since they appear in only once cell in that last photograph.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is it that you want to do with the value now that you have it in the CODE variable in the WORK.CODE dataset?&lt;/P&gt;
&lt;P&gt;Are you going to write it to a file?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Move it to some other database?&lt;BR /&gt;Try to execute it as SAS code?&amp;nbsp; SAS doesn't care whether you have extra line breaks in the code.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723644#M21684</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-04T21:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert multiple line text into "JSON 1 line" format</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723646#M21685</link>
      <description>&lt;P&gt;Note that the 64K limit on macro variables is probably going to be less of problem than the 32K limit on character variables in SAS datasets.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 21:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723646#M21685</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-04T21:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: Convert multiple line text into "JSON 1 line" format</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723812#M21707</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/78975"&gt;@gwootton&lt;/a&gt;&amp;nbsp; thanks for your responses&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;" lang="pl"&gt;1. The main plan to have a macro that can do a copy (B) of Job Definition (A) with the same code and the parameters. I had this question some time ago and closed it a bit too early, before solving all the steps (&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;&lt;A href="https://communities.sas.com/t5/Administration-and-Deployment/Copy-Job-Definition-using-REST-API-or-CLI/m-p/719822#M21553" target="_blank"&gt;Solved: Re: Copy Job Definition using REST API or CLI - SAS Support Communities&lt;/A&gt;)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;" lang="pl"&gt;My plan is:&lt;/P&gt;
&lt;OL style="margin-left: .375in; direction: ltr; unicode-bidi: embed; margin-top: 0in; margin-bottom: 0in; font-family: Calibri; font-size: 11.0pt; font-weight: normal; font-style: normal;" type="a"&gt;
&lt;LI style="margin-top: 0; margin-bottom: 0; vertical-align: middle;" value="1"&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt; font-weight: normal; font-style: normal;"&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt; font-weight: normal; font-style: normal;"&gt;Extract CODE and PARAMETERS from the the Job (A). We can do it with&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;PRE&gt;GET &amp;lt;server&amp;gt;/jobDefinitions/definitions/&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI lang="pl" style="margin-top: 0; margin-bottom: 0; vertical-align: middle;"&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;Create an input JSON file for Job creation, using code and parameters from the Job (A), new name of the job and parent folder&lt;/SPAN&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;There is still 1 step do be done, I would like to set the input parameters for Job(B) creation based on a code from job (A).&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI lang="pl" style="margin-top: 0; margin-bottom: 0; vertical-align: middle;"&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;Create a Job B based on the new input file.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;1. I have a job with this code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let test_var=Hello SAS!;&lt;BR /&gt;%put &amp;amp;test_var;&lt;BR /&gt;/* We can add some comment */&lt;BR /&gt;data a;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=a; &lt;BR /&gt;quit;&lt;/PRE&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;
&lt;P&gt;2. I can export the content of this job with the parameters using REST API query:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC HTTP METHOD="GET" oauth_bearer=sas_services OUT=rep_id
URL="http://pvmict002.health.fgov.be/jobDefinitions/definitions/7a0c60aa-393f-42a8-96b7-21831400f4b4";
HEADERS "Accept"="application/vnd.sas.job.definition+json";
RUN;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;After the extraction the code from the Job:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dandycomp_0-1614934453552.png" style="width: 765px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55490i18969E268BDAC6FE/image-dimensions/765x23?v=v2" width="765" height="23" role="button" title="dandycomp_0-1614934453552.png" alt="dandycomp_0-1614934453552.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The full file&amp;nbsp;&lt;SPAN&gt;rep_id.txt attached.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;3. We need to create a new JSON file. In the line "code" put the code extracted in previous step. The new input file should look like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;{
"version":1,
"name":"New Job with old code",
"description":"Some description",
"type":"Compute",
"parameters":[{"version": 1,
"name": "_contextName",
"defaultValue": "SAS Job Execution compute context",
"type": "CHARACTER",
"label": "Context Name",
"required": false}],
&lt;FONT color="#FF0000"&gt;"code":"%let test_var=Hello SAS!;\n%put &amp;amp;test_var;\n/* We can add some comment */\n\tset sashelp.class;\nrun;\nproc print data=a; \nquit;"&lt;/FONT&gt;
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;I'm looking for a good way to extract the "code" value and put it into the file. Perfectly to not have limitations of 65k of macro length and 32k of max size of column (thanks for a good remark).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/78975"&gt;@gwootton&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;It seems we have to exchange \n \t symbols to text(not to delete). I'm also not sure it would be enough or we need some extra "masking" of special characters.&amp;nbsp; When I created a question I was thinking about some sas function similar to&amp;nbsp;htmlencode(string) but for JSON. But it probably was the wrong way, and I should check another solution.&amp;nbsp;&lt;/SPAN&gt;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 09:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723812#M21707</guid>
      <dc:creator>idziemianczyk</dc:creator>
      <dc:date>2021-03-05T09:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Convert multiple line text into "JSON 1 line" format</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723863#M21709</link>
      <description>&lt;P&gt;You could replace the newline and tab characters \n and \t with their literal values by specifying \\n in the replacement field for prxchange.&lt;BR /&gt;&lt;BR /&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data items;
set init.root;
code=prxchange('s/\n/\\n/', -1, code);
code=prxchange('s/\t/\\t/', -1, code);
keep code;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Replace \\n and \\t with nothing and it will remove them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data items;
set init.root;
code=prxchange('s/\n//', -1, code);
code=prxchange('s/\t//', -1, code);
keep code;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="demo.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55496iF9763F906F06AE3A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="demo.png" alt="demo.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 13:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Convert-multiple-line-text-into-quot-JSON-1-line-quot-format/m-p/723863#M21709</guid>
      <dc:creator>gwootton</dc:creator>
      <dc:date>2021-03-05T13:59:27Z</dc:date>
    </item>
  </channel>
</rss>

