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

Addition of list mapping #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

KernelDeimos
Copy link

@KernelDeimos KernelDeimos commented May 30, 2018

This commit allows map queries on lists. Performing a map query on a list results in a new list, where each element is the element at the queried key of each object in the list that was queried. (mind the word-salad; I couldn't think of a better way to accurately explain it)

Example

JSON

{
  "test": [
    {
      "name": "elgs"
    },
    {
      "name": "enny"
    },
    {
      "name": "sam"
    }
  ]
}

Code

input.Query(test.name) // ["elgs", "enny", "sam"]

@elgs
Copy link
Owner

elgs commented May 30, 2018

Thanks for the code. Just a quick question, would it conflict with the following JSON data semantically?

{
  "test": {
    "name": ["elgs", "enny", "sam"]
  }
}

@KernelDeimos
Copy link
Author

I just edited the example to remove my commas (which would've caused a syntax error)

I just tested my example and the one you just provided - each outputs the expected results. Semantically, I suppose it does, but I don't think that's a problem; in order to write a query you already have to make an assumption about the structure of the data.

Let me know if this answers your question

@KernelDeimos
Copy link
Author

An alternative might be to require the query to be test.[*].name, which is what I was originally going to do, but I decided test.name was more elegant; If the former syntax was required, it would imply you have two "types" of lists, a list-that-you-are-not-allowed-to-map list and a list-that-you-can-map list

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

Successfully merging this pull request may close these issues.

2 participants