s-yadav / jsonQ

A JavaScript library to make manipulation and extraction of data from a JSON very easy and fast.
MIT License
202 stars 69 forks source link

value function is missing #10

Closed gorru closed 8 years ago

gorru commented 8 years ago

Hi. In my json I have many nodes named value. When I check the output of the find function and try to call the value() function I noticed that the function is overridden by the a value property of type array. How can I fix this behaviour? Thanks in advance.

s-yadav commented 8 years ago

Can you send a sample json or setup a jsfiddle/codepen ?

pbosse commented 8 years ago

Got the same issue. It might even be a bigger problem, not sure. So anytime you try to find something that has any function: value, sort, each, filter etc... inside your json, it will fail.
Maybe adding a _ before any of those function calls would solve the issue? Like: jsonq._value() this way it wouldn't be overwritten.

{properties: { choices: [ { label: 'Foo', value: 'Bar' }, { label: 'Foo2', value: 'Bar2' } ] }}

pbosse commented 8 years ago

We fixed the issue by mapping the function with the same name, like so: jsonQ.prototype._value = jsonQ.fn.value

And then using _value instead of value.

But really this should be fixed in jsonQ code so that it supports any json object that is passed.

s-yadav commented 8 years ago

This seems to be a big issue, I will look into it for the possible fix.

s-yadav commented 8 years ago

Fixed on v1.1.0 . Let me know if you guys find any issue with new release.

pbosse commented 8 years ago

Thanks for the quick turn around. Seemed to be working. 👍