Skip to content
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

Select single value, not an array #23

Closed
caseycrites opened this issue Jun 23, 2011 · 1 comment
Closed

Select single value, not an array #23

caseycrites opened this issue Jun 23, 2011 · 1 comment

Comments

@caseycrites
Copy link
Contributor

I've been trying to get this to work for a bit now and can't seem to figure it out. What I'm trying to do is simply return a value instead of an array that contains a single value. For example, given this json:

{this: "is", some: {test: "json"}}

and this JSONSelect query:

.some > .test

is there a way to get back simply "json", instead of ["json"]? I know I can index the array when the result comes out, but I'd really prefer to be able to state in my JSONSelect query that I just want a value and not an array.

@lloyd
Copy link
Owner

lloyd commented Jun 23, 2011

what would you like match to do if there is more than one node that matches?

How about this, have a look at the source. match is built upon foreach, so you can implement a new match function with whatever semantics you're after at a higher level. for reference, here's the match implementation:

https://github.com/lloyd/JSONSelect/blob/master/src/jsonselect.js#L493-498

@lloyd lloyd closed this as completed Jun 23, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants