Get Json from URL and log it to txt file - json

I have a link that will output some json when I browse to it in a web browser, and I get a json response like this: {"totalClients":6514}. Is there a bash script I can use to put the number of "total clients" into a txt file every minute?

Can you explain what you mean by graph the data?
You could use any number of libraries to create a graph
on a html page and use AJAX to load the json data into the javascript.

Related

SAS input json into HTML

Im creating an HTML file from SAS like the following
data _null_;
file './test.html';
put '<DOCTYPE html>';
put '<html>';
put '<script>'
put '</script>'
put '</html>'
The problem is that I need to take a SAS dataset, convert it to JSON format and insert it into the HTML file. The pseudo code is:
data _null_;
file './test.html';
put '<DOCTYPE html>';
put '<html>';
put '<script>';
sasDataFrame -> to Json
put 'console.log(sasDataFrame)';
put '</script>'
put '</html>'
I know that proc JSON allows me to convert SAS dataset to Json, but i don't know how to embed the string result into an HTML through this sort of put statement.
Anyone knows how to accomplish this?
Create the JSON file as a text file using PROC JSON or whatever method you want. Then write the contents of that file into your HTML file.
So let's assume you have pointed the fileref JSON to file with the JSON text in it.
Now first write the header information, then the contents of the file, then the trailing information.
With your simple example you could do it all in one data step. Just read the lines from the JSON text file and write them to the HTML file you are creating.
data _null_;
file './test.html';
if _n_=1 then put
'<DOCTYPE html>'
/ '<html>'
/ '<script>'
;
if eof then put
'</script>'
/ '</html>'
;
infile json end=eof;
input;
put _infile_;
run;
For more complex file generation you can use multiple data steps to construct the HTML file. Just use MOD option on the FILE statement to append text to an existing file instead of making a new file.
Streaming web content like this is an antipattern!!
Rather than fiddle around with put statements, why not serve your index.html through the web server, and send the data from SAS directly as a pure JSON payload?
Here's a repo we created that will let you talk to SAS from frontend: https://github.com/sasjs/adapter
And here's another one with a ready-made web app you can use as a starting point: https://github.com/sasjs/minimal-seed-app
Whilst plugging SASjs (an open source tool my team created) I'll also point out that by using this approach you can easily deploy and run your web app on Viya and Base SAS as well as SAS 9 BI. It'll also run much faster and be easier to maintain.

How to save response data in to CSV in Jmeter

I am trying to save Jmeter response in CSV file. I have tried some of the answers from StackOver Flow but those are not working.
Can anyone suggest me how can I achieve this?
Note: I have tried this and this.
Most probably it is something not feasible when it comes to CSV files as response data can have delimiter characters which will break your CSV file structure. For example if you use comma as delimiter and your response data contains commas - it will be not possible to save the response into a single CSV "cell".
If you need to save the response data I would recommend using XML format of the .jtl results file for this. You can amend JMeter's default result file configuration as follows:
Add next lines to user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data=true
That's it, next time you run JMeter in command-line non-GUI mode as:
jmeter -n -t test.jmx -l result.xml
the result.xml file will contain the response data which can be examined using either View Results Tree listener or XML viewer/editor of your choice.
More information: How to Save Response Data in JMeter
If the response of your request can be stored in csv then you can use one of the following
'Save Responses to a file' in Listeners.
Capture the response using regular expression extractor and write the value to a file in Beanshell code.

Polymer:how to handle csv file upload and convert to json and send to server

i want to handle a requirement in polymer webcomponents where user can upload csv file from ui and csv file can be parsed to json and sent to server ,i searched and found for vaadin upload,looked over the api but i am not sure how to receive the csv file and convert to json and sent to server,can anyone show a jsfiddle of vaadin upload or any other web component to handle this scenario?
First of all, I am wondering why you would not simply do the conversion on the server side.
In this case, you would be able to use the vaadin-upload directly indeed.
Here is a snippet that would upload all files to the example.com server, and only allow CSV files.
<vaadin-upload target="https://example.com/upload" method="POST" accept="text/csv">
</vaadin-upload>
There are plenty of resources on how to convert CSV files to JSON.
Here is a snippet
And here is a node library
If you really wanted to do the conversion client side, then I would suggest to create an element that would embed a vaadin-upload, and convert the Files array to Json before manually calling the uploadFiles method.

how to retrieve json file data in elastic search using sense plugin

I am new to elastic search. I am using sense plugin. While i am trying to retrieve data from JSON file using command
POST/bank/accounts/_bulk?pretty #accounts.json
and the output in sense console is giving like:
Request failed to get to the server (status code: 0):
I want to know which command should I type in Sense to retrieve data from JSON file.
I got the output.I have just copied the total content in the json file and paste it in sense editor n got the output
Thank you
no need to paste the content to sense editor.
just get postman from https://www.getpostman.com/docs/environments give it the file location with /bank/accounts/_bulk?pretty command.

Google Charts using JSON (without Webserver!)

So I want to create a chart using Google Chart API. The problem is following:
I need to create a chart which would use JSON data for the Output.
Example:
I am creating a BarChart which should show Montly Income. Each bar should represent X value of income. But this income changes monthly and I dont want to update the new numbers (as there are plenty) manually by writting them inside the JSON structure (I will use PERL scripts that will gather the new data).
I have read plenty on ther web, but all are using JSON COMBINED WITH PHP ! But I do not have a Web Server. What I want is to create a JSON FOLDER on my desktop, which will contain 100 JSON files inside it.
And when I browse my HTML page, I will click on Monthly Income (May) and this should open a new HTML page which should have some sort of INCLUDE or call function, which should call a SPECIFIC JSON file from the JSON folder on my computer that is coresponded with the path I have chosen on my webpage (in this case Monthly income (May)).
I think my problem is MORE SIMPLE than the method with PHP updating, because I am not worried with the updates - I will update my text files with PERL script. I just need a way, how to include a JSON file into my HTML script, without using PHP or any of these WEB SERVER related stuff.
Any ideas / suggestion ?
Thanks,
David
You can't reliably do it cross-browser with JSON because some browsers block ajax calls from local files (e.g., file:// URLs). But you can do it with JSON-P.
You create the files like this:
dataCallback(/*...JSON here...*/)
E.g.:
dataCallback({
"foo": "bar"
});
...and use this to load the relevant:
<script>
function dataCallback(data) {
// Here, the data will be the deserialized (parsed) data
}
</script>
<script src="/path/to/jsonp/file"></script>
Basically this is using JavaScript, rather than JSON, but where the data file although technically code is really just a function call with the data in the argument.