'Copy nested array into plain one when it is only empty
How do I copy one nested array (urls2.url_breed) into an empty array url_alternative only if this one is empty like in this case? There are some cases when it is not empty and I am not interested to touch it,
{
"breed": "Cavalier King Charles Spaniel",
"url_alternative": [],
"urls2": [
{
"_id": {
"$oid": "627c04199569b8c2f566d1d3"
},
"breed": "Cavalier King Charles Spaniel",
"url_breed": [
"url1", "url2"
]
}
]
}
Desired output:
{
"breed": "Cavalier King Charles Spaniel",
"url_alternative": [
"url1" , "url2"
],
"urls2": [
{
"_id": {
"$oid": "627c04199569b8c2f566d1d3"
},
"breed": "Cavalier King Charles Spaniel",
"url_breed": [
"url1", "url2"
]
}
]
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|