I have a large JSON file that I am using JQ to pair down to only those elements I need. I have that working but there are some values that are string in all caps. Unfortunately, while jq has ascii_downcase and ascii_upcase, it does not have a built in function for uppercasing only the first letter of each word.
I need to only perform this on brand_name and generic_name, while ensure that the manufacturer name is also first letter capitalized with the exception of things like LLC which should remain capitalized.
Here's my current jq statement:
jq '.results[] | select(.openfda.brand_name != null or .openfda.generic_name != null or .openfda.rxcui != null) | select(.openfda|has("rxcui")) | {brand_name: .openfda.brand_name[0], generic_name: .openfda.generic_name[0], manufacturer: .openfda.manufacturer_name[0], rxcui: .openfda.rxcui[0]}' filename.json > newfile.json
This is a sample output:
{
"brand_name": "VELTIN",
"generic_name": "CLINDAMYCIN PHOSPHATE AND TRETINOIN",
"manufacturer": "Almirall, LLC",
"rxcui": "882548"
}
I need the output to be:
{
"brand_name": "Veltin",
"generic_name": "Clindamycin Phosphate And Tretinoin",
"manufacturer": "Almirall, LLC",
"rxcui": "882548"
}