I want to create JSON array for emr steps. I have created the array for single json string. Here is my bash code -
export source="s3a://sourcebucket"
export destination="s3a://destinationbucket"
EMR_DISTCP_STEPS=$( jq -n \
--arg source "$source" \
--arg destination "$destination" \
'{
"Name":"S3DistCp step",
"HadoopJarStep": {
"Args":["s3-dist-cp","--s3Endpoint=s3.amazonaws.com", "'"--src=${sourcepath}"'" ,"'"--dest=${destinationpath}"'"],
"Jar":"command-runner.jar"
},
"ActionOnFailure":"CONTINUE"
}' )
output
echo $EMR_DISTCP_STEPS
[{ "Name": "S3DistCp step", "HadoopJarStep": { "Args": [ "s3-dist-cp", "--s3Endpoint=s3.amazonaws.com", "--src=s3a://sourcebucket", "--dest=s3a://destinationbucket" ], "Jar": "command-runner.jar" }, "ActionOnFailure": "CONTINUE" }]
Now I want to create JSON array with multiple source and destination output
[{ "Name": "S3DistCp step", "HadoopJarStep": { "Args": [ "s3-dist-cp", "--s3Endpoint=s3.amazonaws.com", "--src=s3a://sourcebucket1", "--dest=s3a://destinationbucket1" ], "Jar": "command-runner.jar" }, "ActionOnFailure": "CONTINUE" },
{ "Name": "S3DistCp step", "HadoopJarStep": { "Args": [ "s3-dist-cp", "--s3Endpoint=s3.amazonaws.com", "--src=s3a://sourcebucket2", "--dest=s3a://destinationbucket2" ], "Jar": "command-runner.jar" }, "ActionOnFailure": "CONTINUE" },
{ "Name": "S3DistCp step", "HadoopJarStep": { "Args": [ "s3-dist-cp", "--s3Endpoint=s3.amazonaws.com", "--src=s3a://sourcebucket3", "--dest=s3a://destinationbucket3" ], "Jar": "command-runner.jar" }, "ActionOnFailure": "CONTINUE" }]
How to generate JSON Array with multiple sources and destinations (JSON string) in Bash?
'foo', the quote'is an instruction to your shell, not part of the argumentfoo, and you want to leave it out of any JSON or other higher-level representation of the data.jqis such a language, just as much as Python is, and also happens to be already tagged in the question. :)