cURL returns JSON data - json

When typing the following cURL into cmd prompt, "**curl https://jsonplaceholder.typicode.com/posts**",
it returns an array of JSON data. (online rest api)
I have been given a command, "curl -u recruiter:supersecret localhost:3000/raw". When typed in the command should return json data.
Using json-server I was able to create a json file and host it locally. When typing the url it created, it displayed the JSON data.
How can I use that specific command to return json data?
Can anyone please provide some direction on how to go about doing this.
Thanks.

Not clear what your question is or what you're asking. If you're curling for /raw, the json file you're hosting with json-server should have a raw field like:
{ "raw": "some test data" }
read the getting started section for json-server:
https://github.com/typicode/json-server

Related

Can we POST the data present in json format using wget in linux

I want to know is there a possibility to post the data in json format to a dashboard from linux server.
My JSON data is in the below format.
{
"data":"{\"actiontodo\":\"Action to do for test nr:
1\",\"critical\":\"LOW\",\"fixstatus\":\"NOTCONCERN\",\"host\":\"MTR_SOME_HOST\",
\"message\":\"$message\",\"mgsApplication\":\"MTR\",\"sMxtype\":\"PROD\",
\"scriptname\":\"$scriptname\"}",
"msg":"NotificationReceiveDTO without dict to send at: 2020-06-07T11:14:09.794 Created at: 2020-
06-07T11:14:09.797",
"msgType":"DATA"
}
From the man page for wget it is possible to post data to website, using either the --post-data=string or --post-file=file argument.

Request a specific variable of JSON stream using bash/terminal

I am working with a flutter web server testing. I writing a simple bash script to fetch some JSON data from API request. The API request dispatch following information as JSON response.
{
"code_version":{
"engine_name":"flutter_renderV1",
"proxy":"10.1.1.1:1090",
"test_rate":true,
"test_density":"0.1",
"mapping_eng":"flutter_default_mapper"
},
"developer_info":{
"developerid":"30242",
"context":true,
"request_timestamp":"156122441"
}
}
Once this received, I saved in to local file named server_response{$id}.json. I need to collect test_density value under code_version data frame. I used several awk, sed command to fetch data, unfortunatly I cannot get the exact output from my terminal.
You need to install powerful JSON querying processor like jq processor. you can can easily install from here
once you install jq processor, try following command to extract the variable from JSON key value
suppose, your file named as server_response_123.json,
jq '.code_version.test_density' server_response_123.json
the output will be shown as,
"0.1"

How to save API request response in Postman to a JSON file when running a collection

I have set up a collection that executes an API request which its payload is a JSON file.
I would like to run this postman collection for several times using different values for a variable that I have set in my request. However, I don't know how to save the API response from my Get request into a JSON file.
I have done the similar procedure as well for the automation test. Here were some steps I took:
Write a script to execute the postman collection test through postman command line interface modules (https://github.com/postmanlabs/newman), where you can store all the command into a string array with different environment variables you want to specify.
[new man collection -e env_var.json --reporters cli,json --reporter-json-export output.json, new man second run, ... ]
For each execution, you can get the response body by nodejs module and dump the result to json format. (similar to: output responseBody somewhere with newman script from postman collection)
Or you can generate the JSON from newman reporter, and parse the JSON to get the informantion you want.
Hope it helps!

Parsing json response to use as next curl request

I'm using Jenkins and curl to post a file in a form that is analyzed and returns an ID that is to be used to download the contents.
My problem is how to parse the json response in order to use as my next curl get request.
This is the post command:
curl --form file=#"%WORKSPACE%\results.zip" https://host.com
This returns a json response like: {"request_id":"XXXXXX","message:null","error":false}
I want to pass the pair "request_id=XXXX" in my next curl request like:
curl https://host.com/downloadreport?request_id=XXXXX
Is there a way to do this? Saving the json response to a file and parsing it somehow? or maybe chaining both requests and manipulating the json response?
Thanks in advance
Found a partial solution:
for /f "tokens=1,2,3,4,5,6 delims=:," %%a in ("%requestId%") do set request=%%a&set id=%%b&set msg=%%c&set contents=%%d&set error=%%e&set code=%%f
It isn't very robust as it requires to know the response setup and sometimes response changes order and can't really know what is in each variable.

Uploading multiple "documents" to IrisCouch from a JSON file

I have a large dataset in JSON format that I would like to upload to IrisCouchDB.
I found the following instructions: http://kxepal.iriscouch.com/docs/1.3/api/database/common.html
But I am a newbie and it also seems to be for a single JSON document. Im afraid I will just create one huge entry and not multiple documents entries which is what I want.
I have NodeJS but I don't have Cradle. Will I need it in order to perform this function? Any help is greatly appreciated!
Oh, no! That's bad idea to reference on docs at my Iris host - that's was preview dev build. Please follow the official docs: http://docs.couchdb.org/en/latest/api/index.html
To update multiple document's you need to use /db/_bulk_docs resource:
curl -X POST http://localhost:5984/db/_bulk_docs \
-H "Content-Type:application/json" \
-d '{"docs":[{"name":"Yoda"}, {"name":"Han Solo"}, {"name":"Leia"}]}'
So you see the format of data you should send to CouchDB? Now it's all depending from you JSON file format. If whole file is an array of objects: just wrap his content into {"docs":..} object. If not: you have to write some small library to convert this file data into the required format.