Somehow I think there must be a one-liner to apply a simple mapping on the command line. In this case the keys in JSON will (as usual) provide context, ensuring that we don't foolishly replace strings that shouldn't.
Suppose we are given a library catalog in a JSON file using the Dewey Decimal Classification
[
{
"Title": "Design Pattern",
"Call Number": "005.12 DES"
},
{
"Title": "Intro to C++",
"Call Number": "005.133 C STR"
}
]
as well as a mapping between Dewey and the Library of Congress call numbers
[
{
"Dewey": "005.12 DES",
"Congress": "QA76.64 .D47 1995X"
},
{
"Dewey": "005.133 C STR",
"Congress": "QA76.73.C153 S77 2013"
}
]
and want to produce the output file:
[
{
"Title": "Design Pattern",
"Call Number": "QA76.64 .D47 1995X"
},
{
"Title": "Intro to C++",
"Call Number": "QA76.73.C153 S77 2013"
}
]
Does this still fit within the one-line set of transformations that jq
will handle?