<?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 Posting Json data on a SAS server is returning an error message  Unexpected token '&amp;lt;' in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Posting-Json-data-on-a-SAS-server-is-returning-an-error-message/m-p/981115#M379031</link>
    <description>&lt;P&gt;&lt;BR /&gt;I am trying to write Json data back to the SAS server.&amp;nbsp; The code creates a temp file but it is empty and in the response.json() I get an error&amp;nbsp;something went wrong: Unexpected token '&amp;lt;' ,",html&amp;gt; &amp;lt;t"... is not valid JSON.&lt;/P&gt;&lt;P&gt;I am including both the JavaScript and the server side code.&lt;/P&gt;&lt;P&gt;JavaScript Code:&lt;/P&gt;&lt;P&gt;const jsonData = {&lt;BR /&gt;"name": "value",&lt;BR /&gt;"id": 123&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;fetch('YOUR_SAS_SERVER_ENDPOINT_URL', { /* The url is a stored process the code is listed in the&lt;BR /&gt;method: 'POST', // Specify the method&lt;BR /&gt;headers: {&lt;BR /&gt;'Content-Type': 'application/json', // Inform the server the data type&lt;BR /&gt;'Accept': 'application/json' // Indicate expected response type (optional)&lt;BR /&gt;},&lt;BR /&gt;body: JSON.stringify(jsonData) // Convert the JS object to a JSON string&lt;BR /&gt;})&lt;BR /&gt;.then(response =&amp;gt; response.json()) // Process the response (this is where I get the error)&lt;BR /&gt;.then(data =&amp;gt; console.log('Success:', data))&lt;BR /&gt;.catch((error) =&amp;gt; {&lt;BR /&gt;console.error('Error:', error);&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Server Side Code;&lt;/P&gt;&lt;P&gt;/* Reference the uploaded/posted JSON data from the input stream */&lt;BR /&gt;filename indata temp; /* The file gets created but 0 size and no data*/&lt;/P&gt;&lt;P&gt;/* Use the JSON engine to provide read-only sequential access to JSON data */&lt;BR /&gt;libname myjson json fileref=indata;&lt;/P&gt;&lt;P&gt;/* Process the data (e.g., copy to a work dataset and print) */&lt;BR /&gt;proc copy inlib=myjson outlib=work;&lt;BR /&gt;select alldata; /* 'alldata' is a common default table name created by the JSON engine */&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;title 'Data Received from JavaScript POST';&lt;BR /&gt;proc print data=work.alldata;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/* Clear the libname reference */&lt;BR /&gt;libname myjson clear;&lt;/P&gt;&lt;P&gt;/* Optionally, write a JSON response back to the client */&lt;BR /&gt;data _null_;&lt;BR /&gt;file _webout type='application/json';&lt;BR /&gt;put '{ "status": "Data successfully received and processed by SAS" }';&lt;BR /&gt;run;&lt;BR /&gt;To create the table I am using code similar to:&lt;BR /&gt;data _null_;&lt;BR /&gt;file _webout;&lt;BR /&gt;put '&amp;lt;html&amp;gt;';&lt;BR /&gt;put '&amp;lt;head&amp;gt;';&lt;/P&gt;&lt;P&gt;I have tried everything specially on the server side. The Temp file is always 0 size.&lt;/P&gt;</description>
    <pubDate>Fri, 19 Dec 2025 17:37:53 GMT</pubDate>
    <dc:creator>Magued</dc:creator>
    <dc:date>2025-12-19T17:37:53Z</dc:date>
    <item>
      <title>Posting Json data on a SAS server is returning an error message  Unexpected token '&lt;'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Posting-Json-data-on-a-SAS-server-is-returning-an-error-message/m-p/981115#M379031</link>
      <description>&lt;P&gt;&lt;BR /&gt;I am trying to write Json data back to the SAS server.&amp;nbsp; The code creates a temp file but it is empty and in the response.json() I get an error&amp;nbsp;something went wrong: Unexpected token '&amp;lt;' ,",html&amp;gt; &amp;lt;t"... is not valid JSON.&lt;/P&gt;&lt;P&gt;I am including both the JavaScript and the server side code.&lt;/P&gt;&lt;P&gt;JavaScript Code:&lt;/P&gt;&lt;P&gt;const jsonData = {&lt;BR /&gt;"name": "value",&lt;BR /&gt;"id": 123&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;fetch('YOUR_SAS_SERVER_ENDPOINT_URL', { /* The url is a stored process the code is listed in the&lt;BR /&gt;method: 'POST', // Specify the method&lt;BR /&gt;headers: {&lt;BR /&gt;'Content-Type': 'application/json', // Inform the server the data type&lt;BR /&gt;'Accept': 'application/json' // Indicate expected response type (optional)&lt;BR /&gt;},&lt;BR /&gt;body: JSON.stringify(jsonData) // Convert the JS object to a JSON string&lt;BR /&gt;})&lt;BR /&gt;.then(response =&amp;gt; response.json()) // Process the response (this is where I get the error)&lt;BR /&gt;.then(data =&amp;gt; console.log('Success:', data))&lt;BR /&gt;.catch((error) =&amp;gt; {&lt;BR /&gt;console.error('Error:', error);&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Server Side Code;&lt;/P&gt;&lt;P&gt;/* Reference the uploaded/posted JSON data from the input stream */&lt;BR /&gt;filename indata temp; /* The file gets created but 0 size and no data*/&lt;/P&gt;&lt;P&gt;/* Use the JSON engine to provide read-only sequential access to JSON data */&lt;BR /&gt;libname myjson json fileref=indata;&lt;/P&gt;&lt;P&gt;/* Process the data (e.g., copy to a work dataset and print) */&lt;BR /&gt;proc copy inlib=myjson outlib=work;&lt;BR /&gt;select alldata; /* 'alldata' is a common default table name created by the JSON engine */&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;title 'Data Received from JavaScript POST';&lt;BR /&gt;proc print data=work.alldata;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/* Clear the libname reference */&lt;BR /&gt;libname myjson clear;&lt;/P&gt;&lt;P&gt;/* Optionally, write a JSON response back to the client */&lt;BR /&gt;data _null_;&lt;BR /&gt;file _webout type='application/json';&lt;BR /&gt;put '{ "status": "Data successfully received and processed by SAS" }';&lt;BR /&gt;run;&lt;BR /&gt;To create the table I am using code similar to:&lt;BR /&gt;data _null_;&lt;BR /&gt;file _webout;&lt;BR /&gt;put '&amp;lt;html&amp;gt;';&lt;BR /&gt;put '&amp;lt;head&amp;gt;';&lt;/P&gt;&lt;P&gt;I have tried everything specially on the server side. The Temp file is always 0 size.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Dec 2025 17:37:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Posting-Json-data-on-a-SAS-server-is-returning-an-error-message/m-p/981115#M379031</guid>
      <dc:creator>Magued</dc:creator>
      <dc:date>2025-12-19T17:37:53Z</dc:date>
    </item>
  </channel>
</rss>

