Open ronag opened 8 years ago
The problem I have here it that I would like to be able to insert an element into an array without knowing if the array exists or not, and if it doesn't exists it should be created:
Which I thought would be possible with the following:
[{
p: ['tags'],
oi: [],
}, {
p: ['tags', 0],
li: 'archived',
}],
However, this will always result in tags: ['archived']
regardless if previous elements exists or not...
As a side-note, this is also a huge problem with inversion. It's currently possible to have:
{
"tags": ["archived"]
}
and then perform this op on it:
[
{
"p": ["tags"],
"oi": []
}
]
...resulting in this document:
{
"tags": []
}
Then when you try to invert the previous operation, the op doesn't know what was originally there when it replaced it, so it just deletes the field, resulting in:
{}
...which is not what I had before.
In my opinion, in the case where a path is being overwritten, json0
should throw
, because it violates the integrity of the operation, as demonstrated above.
Aha, I've just seen that my issue is probably addressed in this PR: https://github.com/ottypes/json0/pull/19
For
{p:PATH, oi:NEWVALUE}
The documentation says:
However, if they key exists it currently will overwrite it...
Not sure what the correct behaviour is?