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

Support for query by key using data from a list #85

Open
jeking3 opened this issue Apr 8, 2019 · 0 comments
Open

Support for query by key using data from a list #85

jeking3 opened this issue Apr 8, 2019 · 0 comments

Comments

@jeking3
Copy link

jeking3 commented Apr 8, 2019

I have some data where there are "named references" to other objects in other parts of the document stored as a string, for example:

{
  "beverage": {"soda": {
    "lemonlime": {"plants": [
      "Atlanta",
      "Chicago"
    ]},
    "rootbeer": {"plants": [
      "Chicago",
      "Denver"
    ]}
  }},
  "manufacturing": {"plant": {
    "Atlanta": {"capacity": 500000},
    "Denver": {"capacity": 300000},
    "Chicago": {"capacity": 200000}
  }}
}

I was unable to find a way to access the appropriate manufacturing plant using ObjectPath as each record is a named dictionary rather than a list item. So if I wanted to find out the total capacity possible for each of the two sodas using ObjectPath, is there a way to do that?

I was trying to do something like this: sum($.manufacturing.plant.[$.beverage.soda.lemonlime.plants].capacity) but I was not able to set a part of the path to the value that is stored somewhere else. All of the selectors appear to be list based, is that correct?

Some information I found elsewhere indicates that if the name of the plant were a value in each record it would be possible, but with the name of the plant as a key to the record itself that there is no lookup directive that can do this. I'd prefer not to have to rewrite these structures just to be able to use ObjectPath to look up information in this way.

If there were another operator or function that could do this, it would be useful:

sum($.manufacturing.plant.&[$.beverage.soda.lemonlime.plants].capacity -> 700000

for example, given .* would be all names, perhaps .& could be selected names?

If the data were structured in another way, where the references were fully qualified dotted names into the tree:

{
  "beverage": {"soda": {
    "lemonlime": {"plants": [
      "manufacturing.plant.Atlanta",
      "manufacturing.plant.Chicago"
    ]},
    "rootbeer": {"plants": [
      "manufacturing.plant.Chicago",
      "manufacturing.plant.Denver"
    ]}
  }},
  "manufacturing": {"plant": {
    "Atlanta": {"capacity": 500000},
    "Denver": {"capacity": 300000},
    "Chicago": {"capacity": 200000}
  }}
}

A desired lookup on this would be:

sum($.&[$.beverage.soda.lemonlime.plants].capacity -> 700000

Thoughts?

@jeking3 jeking3 changed the title Support for query by key Support for query by key using data from a list Apr 8, 2019
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

1 participant