Request a specific variable of JSON stream using bash/terminal - json

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"

Related

Get a github folder it's contents as a json file

if I construct this URL, I can see the contents of the images folder as a json in Firefox.
https://api.github.com/repos/DessoCode/ESP32/contents/Images?ref=main
However, this doesn't seem to be a true json since my parser doesn't parse this. I'm using an ESP32 and Arduino.
The code works with a true json link. (For example: http://arduinojson.org/example.json)
My question is: How do I change the first URL so it has a .json extension?
Thank you so much!
I figured it out, I needed to serialize the input stream first, then I could deserialize it and use the values.
The alternative is to install GitHub CLI gh (through one of the linux_arm64 packages), and use gh api to execute the API call... with -q or --jq <string> to query and select values from the response using jq syntax.
No need to serialize/de serialize.
gh api repos/DessoCode/ESP32/contents/Images?ref=main --jq ".[].path"
Images/robot.bmp
Images/skulltest.bmp
Images/yellow.bmp

cURL returns JSON data

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

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.

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!

jmeter load testing , Parameterization

I am running a HTTP request test in jmeter where I send a json input. For example:
{ "id":"0", "fieldvalue":"sanket","Source":"todays date" }
I need to parametrize this so that for each thread iteration a different value for id, fieldvalue, source is chosen, possibly from a json file only (not CSV file). Is this possible?
Everything is possible. Here are the options
JMeter can read almost any files. Check out the following functions:
__FileToString()
_StringFromFile()
You can also use HTTP Request sampler to read the file, just use file as protocol and UNC path.
Values for parametrization can be obtained using JSON Path PostProcessor. See:
JSONPath - XPath for JSON - for JSON Path language overview and syntax
Advanced Usage of the JSON Path Extractor in JMeter - for some not obvious scenarios covered