Comments (8)
Hmm, i agree it's inconsistent. How should we solve it?
The idea of dict was to return a jsonpointer/value map. I'm not sure if we should include empty arrays.
I think it should be easy to create an object with #dict, process it and apply the values to an other object using #set. If we include empty arrays the result will depend on the order the values are applied.
Maybe the best option is to deprecate #has since this can be easily achieved by #get.
from json-pointer.
I think that #dict
should return a path for an empty array because it is a valid path, it exists in object and it's value isn't undefined
. That is all props that are not equal to undefined must be returned by #dict
as deep as possible. I tried to fix it in this pull request
But I agree with you according #has
method since it useless (personally I never had cases where #has
had advantages over the #get
)
from json-pointer.
What about non empty arrays and objects?
{
arr: [1],
obj: { example: 4 }
}
To have a consistent behaviour #dict
should return the following:
{
'/arr': [1],
'/arr/0': 1,
'/obj': { example: 4 },
'/obj/example': 4
}
In the case above /arr
and /obj
are also valid path that exist and their values are not undefined
. We could change it to behave like that, but i am not sure yet if this it's a good idea.
from json-pointer.
I agree with you and although both /arr/0
and /arr
paths are not undefined
, /arr/0
path is deeper then /arr
so it must be returned by #dict
(and my opinion that /arr
shouldn't be returned in that case).
So my vote for:
{
'/arr/0': 1,
'/obj/example': 4
}
from json-pointer.
Ok, convinced.
I think the iteration functionality should be moved from #dict
to #walk
.
So #dict
can just #walk
and return only the deepest values.
#walk
should execute the callback for every json-pointer, not just the deepest ones. We could add an optional descend callback to #walk
that defaults to:
(value) ->
type = {}.toString.call(value)
type == '[object Object]' or type == '[object Array]'
And #has
gets removed.
What do you think about this changes?
from json-pointer.
Nice, waiting for update!
from json-pointer.
Any progress on this issue? Actually I'm waiting for the fix or if it is not possible to complete in near future, please merge my pull request, and publish new version in npm.
from json-pointer.
@manuelstofer I'm still waiting when you fix this issue and update npm package
from json-pointer.
Related Issues (14)
- Add thrown exceptions in documentation
- Got a license for this? HOT 1
- json-ponter "/" throws "Invalid reference token: " HOT 1
- An option for .get to return undefined instead of throwing if pointer does not exist HOT 6
- The pointer.dict function crashes when object contains an array HOT 3
- Switch to the new travis platform HOT 1
- Support relative pointers?
- Missing remove() HOT 3
- CVE-2021-23820 HOT 6
- Selector support and docs
- NVM: duplicate of below. (CVE-2021-23820)
- compile([]) returns "/" HOT 1
- Funky whitespace in api.walk
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-pointer.