How can I create a JSON object from an associative array in shell using jo?
2
votes
3
answers
2138
views
I know about https://unix.stackexchange.com/questions/625501/how-to-create-json-from-associative-array but that's not my problem.
I have this associative array:
declare -A aliases
aliases[Index]=components/Index/Exports
aliases[Shared]=components/Shared/Exports
aliases[Icons]=components/Icons/Exports
Now I need to convert this associative array into this JSON:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"Index": ["components/Index/Exports"],
"Shared": ["components/Shared/Exports"],
"Icons": ["components/Icons/Exports"],
}
}
}
I want to use jo
and jq
. But I can't come up with the nesting.
I tried this code:
jo -p compilerOptions[baseUrl]=. compilerOptions[paths]="$(jo -p a ${Aliases[@]})"
But it does not even run.
Asked by Saeed Neamati
(841 rep)
Jun 30, 2022, 01:38 PM
Last activity: Jun 22, 2024, 07:48 PM
Last activity: Jun 22, 2024, 07:48 PM