Consider the following a snippet from my package.json
"dependencies": {
"@types/lodash.camelcase": "^4.3.6",
"@types/lodash.kebabcase": "^4.1.6",
"@types/lodash.lowercase": "^4.3.6",
"@types/lodash.upperfirst": "^4.3.6",
"@types/mime": "^2.0.3",
"@types/swagger-jsdoc": "^6.0.1",
"async": "^3.2.2",
"aws-arn": "^1.0.1",
}
From this, I want to generate the following string –
@types/lodash.camelcase@^4.3.6 @types/lodash.kebabcase@^4.1.6 @types/lodash.lowercase@^4.3.6 @types/lodash.upperfirst@^4.3.6 @types/mime@^2.0.3 @types/swagger-jsdoc@^6.0.1 async@^3.2.2 aws-arn@^1.0.1
Any idea how to accomplish this?
2
Answers
As
jq
is tagged: Make a valid JSON, then disassemble withto_entries
, andjoin
twice:Demo
Assuming actually valid JSON, you can use string interpolation) and
join
:String interpolation gives you a little more flexibility compared to using join twice. YMMV, and for sample cases join will suffice.