BookmarkSubscribeRSS Feed
Magued
Fluorite | Level 6


I am trying to write Json data back to the SAS server.  The code creates a temp file but it is empty and in the response.json() I get an error something went wrong: Unexpected token '<' ,",html> <t"... is not valid JSON.

I am including both the JavaScript and the server side code.

JavaScript Code:

const jsonData = {
"name": "value",
"id": 123
};

fetch('YOUR_SAS_SERVER_ENDPOINT_URL', { /* The url is a stored process the code is listed in the
method: 'POST', // Specify the method
headers: {
'Content-Type': 'application/json', // Inform the server the data type
'Accept': 'application/json' // Indicate expected response type (optional)
},
body: JSON.stringify(jsonData) // Convert the JS object to a JSON string
})
.then(response => response.json()) // Process the response (this is where I get the error)
.then(data => console.log('Success:', data))
.catch((error) => {
console.error('Error:', error);
});

 

Server Side Code;

/* Reference the uploaded/posted JSON data from the input stream */
filename indata temp; /* The file gets created but 0 size and no data*/

/* Use the JSON engine to provide read-only sequential access to JSON data */
libname myjson json fileref=indata;

/* Process the data (e.g., copy to a work dataset and print) */
proc copy inlib=myjson outlib=work;
select alldata; /* 'alldata' is a common default table name created by the JSON engine */
run;

title 'Data Received from JavaScript POST';
proc print data=work.alldata;
run;

/* Clear the libname reference */
libname myjson clear;

/* Optionally, write a JSON response back to the client */
data _null_;
file _webout type='application/json';
put '{ "status": "Data successfully received and processed by SAS" }';
run;
To create the table I am using code similar to:
data _null_;
file _webout;
put '<html>';
put '<head>';

I have tried everything specially on the server side. The Temp file is always 0 size.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 0 replies
  • 89 views
  • 0 likes
  • 1 in conversation