HTTP Request for text/plain: How to create a data table?Hi,
I'm working with a customer on httprequest. They get the data as text/plain into a variable "data". The parsing looks like this:
// Parsing
request_headers = AssociativeArray();
request_headers["Accept"] = "text/plain";
request_headers["authorization"] = " Bearer " || bearer_token;
// Http Request
request = HTTPRequest(
Url(url || endpoint),
Method("GET"),
Headers(request_headers),
);
data = request << Send;
In the attached script you will see the output of the log file for data. it is comma seperated, both numeric and character variables.
I struggle to create a data table from this "data" variable. I thought to use "matrix box()" but this will only work for numeric data. I'm stucked but I feel like I'm just to blind to see the obvious. May you can help me?
Thanks,
Martin
Re: HTTP Request for text/plain: How to create a data table?Not an expert on this, but try using "JSON to Data Table( data )". It looks like at least part of what is returned is in JSON format.
MRe: HTTP Request for text/plain: How to create a data table?thanks for the suggestion. The part looking like JSON is a text snippet which is the value of a text variable, so a string of a query saved in a variable. JSON to Datatable does not work as the syntax is incorrect - it misses the brackets and so forth at the start and end and as well the quotations.
how would you bring a list or associative array to a data table?
Re: HTTP Request for text/plain: How to create a data table?You would have to make your best guess as to the structure of the data table given the text file. It looked like table (or section) headers were part of the text, so that is a start. Hopefully, there is information on the site where the HTTP request is being made detailing the structure of the output.
Re: HTTP Request for text/plain: How to create a data table?I may have found a workaround, in case data is a list with the returned text as only element.
//***
Save Text File("$TEMP/DeleteMe.txt", data[1]);
dt = Open("$TEMP/DeleteMe.txt");
rc0 = Delete File( "$TEMP/DeleteMe.txt" );
Char( rc0 );
//***
I will check with the customer if this works. Otherwise I have to check the data type to see what else could be done.
However I wonder if there is a command which allows the text import directly with a variable in a script? Anyone knows that?
PS: Attached the script to generate the data table to understand the structure.
Re: HTTP Request for text/plain: How to create a data table?Update:
the last script work, except I had to use in the first line "data" without index, as the data came back as text rather than a list as I thought.
I still do not see an easy and direct way to get the text into a jmp table without the workaround of saving the table temporarily.