-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about flatten and unflatten #1989
Comments
Related Issue : #1575 IMHO, we can change the array to object when we get |
Yes, there is no exact solution for this. The point you are describing (object keys which can be translated into integers) are ambiguous in this setting. The problem with your described approach is that it would require multi-pass parsing. one to collect all keys for all object/arrays, and then to create the final types. I am not sure whether this would fix the issue. But maybe I miss something. |
In this case, integers can be object keys. |
I had tried to fix this and got some troubles.
Anyway, |
All in all, I fear there is no proper solution for this due to the ambiguity that JSON Pointers have in this regard. |
From #1575 (comment)
I think we can add a parameter into My idea is that in 'unflatten()', we just consider
Example:
|
Keep active. |
The problem is as follows: once value The problem is to sort a list of JSON pointers in that setting, because the choice whether to start an object or array has to be made after every For the example, the order should be
|
I had tried to solve it. But the above troble 2 still exist.
IMO, i think it is ok that in 'unflatten()', we just consider object. I prefer to use object to represent array instead of filling with null values. |
Just considering object in
But i think this can be accepted. |
Now I think I understand what you mean with "the null value" problem. Considering the JSON value {
"/bad/0": "one",
"/bad/11": "two",
"/foo": "bar"
} I think the only unflattened value that makes sense is {
"bad": {
"0": "one",
"11": "two"
},
"foo": "bar"
} because though "0" and "11" could be valid indices for an array, flattening would list all values. This means {
"bad": ["one", null, null, null, null, null, null, null, null, null, null, "two"],
"foo": "bar"
} can not be the unflattened value for the JSON above. This means we must not just create an array if we encounter a number, but also make sure that all numbers are continuous. I have the feeling that the effort to fix this is not really worth it... Any ideas? |
My idea is that in |
Or based on the idea above, we can try to convert those object with continuous numbers key to array after calling |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I had tested that
j.flatten() == j_flatten
is true andj_flatten.unflatten() == j
is false.From the source code, it might just look at the first pointer - if there is a
"0"
reference_token, it will start a new array. And the behavior will cause that under the following cases, we cannot useunflatten()
:when calling
unflatten()
,[json.exception.parse_error.109] parse error: array index 't' is not a number
will be raised.The text was updated successfully, but these errors were encountered: