Im writing bash script for AWS Secret Manager .
Question:
I have one aws secret manager it will contain multiple secret
Example:
aws secretsmanager get-secret-value –secret-id Example | jq -r ".SecretString"
input.json
{"Username":"admin","Password":"admin","Endpoint":"localhost","DatabaseName":"example","Port":"3306"}
Using this command got a json output
Now I want to extract All values like (Username , password,..)
After get all extract values add in another json file called (secondfile.json)
I have another json file it will contain
this is secondfile.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Aurora": {
"Username": "",
"Password": "",
"Endpoint": "",
"DatabaseName": "",
"Port": ""
}
}
Sample Output: extracted values now stored second file.json file in Aurora[] array elements.
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Aurora": {
"Username": "admin",
"Password": "admin",
"Endpoint": "localhost",
"DatabaseName": "example",
"Port": "3306"
}
}
Need Help on do with bash script .
Note: Input.json value not fixed , it may be contain 3 json key/value or n number of key/value
3
Answers
If I understand your question correctly, you simply want to embed/wrap the input document in a top level document.
Output:
The key "Aurora" will contain your input document. If you need only specific fields, then replace
.
with{Username,Password}
Here is one solution how to jq’s
--slurpfile
option to use another file as "template" to format your input and then replace the parts according to your requirements:Or swapping template and input files:
If you can change your "template" file, I would suggest not keeping it as JSON, but make it a jq program instead:
Note that the filter program can be written with shorthand syntax: