I'm trying to replace the value of a key in my original JSON with the value of an object with the corresponding key in another document.
These are my two files: File 1:
{
"-KaM0otlgWxXniYiacFe": {
"-LNxx1IiX6oYTxJ4IXx2": true
},
"-KlJTvbfonIMI_-YfS5R": {
"-LNxx1IbaB-yrZ623hrX": true
}
}
File 2:
{
"-KaM0otlgWxXniYiacFe": {
"a": "-L-b__nH9PlMcz0stDDE",
"b": "-L7ZNKSZy570TlrQUzHM",
"c": "-Kaae3MsQUyViCKPs8Iv"
},
"-KlJTvbfonIMI_-YfS5R": {
"a": "-LAlXKfUUTdYDeCZH-u-",
"b": "-L7ZNKSTnob7w0HXjHr6",
" c": "-KYYicPD7VA9DEF_rus3"
}
}
The goal is to create 3 new files, where the original keys have been replaced with the value of a, b and c in each file.
Desired result when looking against "a":
{
"-L-b__nH9PlMcz0stDDE": {
"-LNxx1IiX6oYTxJ4IXx2": true
},
"-LAlXKfUUTdYDeCZH-u-": {
"-LNxx1IbaB-yrZ623hrX": true
}
}
I have tried using something along the lines of:
cat file1.json | jq --slurpfile file2 file2.json '| map(with_entries(.key = .file2[.key].a'
But I'm feeling rather clueless as I havn't used jq before.
Any help is appreciated.
Update:
How do I handle the scenario where the key from File 1 might not exist in File 2, resulting in the "Cannot use null (null) as object key"?