I have two jsons as follows
JSON 1 -
{
"2021年03月11日": [
{
"14:30:00": 3000
}
],
"2021年03月14日": [
{
"14:30:00": 130
}
]
}
JSON 2 -
{
"2021年03月02日": [
{
"10:30:00": null
}
],
"2021年03月11日": [
{
"10:30:00": null
},
{
"11:30:00": null
},
{
"14:30:00": null
}
],
"2021年03月12日": [
{
"11:30:00": null
}
],
"2021年03月14日": [
{
"14:30:00": null
}
],
"2021年03月15日": [
{
"10:30:00": null
}
]
}
I want to combine these two JSON like below
{
"2021年03月02日": [
{
"10:30:00": null
}
],
"2021年03月11日": [
{
"10:30:00": null
},
{
"11:30:00": null
},
{
"14:30:00": 3000
}
],
"2021年03月12日": [
{
"11:30:00": null
}
],
"2021年03月14日": [
{
"14:30:00": 130
}
],
"2021年03月15日": [
{
"10:30:00": null
}
]
}
But when I use the || operator, this is the result I get
{
{
"2021年03月02日": [
{
"10:30:00": null
}
],
"2021年03月11日": [
{
"14:30:00": 3000
}
],
"2021年03月12日": [
{
"11:30:00": null
}
],
"2021年03月14日": [
{
"14:30:00": 130
}
],
"2021年03月15日": [
{
"10:30:00": null
}
]
}
for some reason it only retrieves only one second level key value pair, is there anyway to fix this?
-
for some reason it only retrieves only one second level key value pair This is a norma: Concatenating two objects generates an object containing the union of their keys, taking the second object's value when there are duplicate keys. postgresql.org/docs/current/functions-json.htmlAkina– Akina2021年03月23日 09:46:53 +00:00Commented Mar 23, 2021 at 9:46
-
Concatenation does not iterate over all document strusture, it operates only on the upper level. So you must unnest your JSONs then nest them back.Akina– Akina2021年03月23日 09:48:41 +00:00Commented Mar 23, 2021 at 9:48
-
Have a look here for a starter: dba.stackexchange.com/questions/287155/… You'll have to add a level to deal with your nesting.Gerard H. Pille– Gerard H. Pille2021年03月23日 09:51:53 +00:00Commented Mar 23, 2021 at 9:51
-
See here or hereuser1822– user18222021年03月23日 12:08:53 +00:00Commented Mar 23, 2021 at 12:08
lang-sql