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

Feature Request: Enhance Syntax for Picking Specific Fields #188

Open
nitaiaharoni1 opened this issue May 22, 2023 · 2 comments
Open

Feature Request: Enhance Syntax for Picking Specific Fields #188

nitaiaharoni1 opened this issue May 22, 2023 · 2 comments
Labels

Comments

@nitaiaharoni1
Copy link

nitaiaharoni1 commented May 22, 2023

Motivation

Ability to select multiple fields from an object in one query.

Current behavior

Currently, to select multiple fields from an object, the user needs to run multiple queries or process the result of a more general query. For example, given the following JSON:

{
  "data": {
    "items": [
      {
        "data": {
          "name": "Apple",
          "color": "red",
          "weight": "150g"
        }
      },
      {
        "data": {
          "name": "Banana",
          "color": "yellow",
          "weight": "120g"
        }
      }
    ]
  }
}

To get the name and color of each item, the user would need to run separate queries for each field: $.data.items[*].data.name and $.data.items[*].data.color.

Desired behavior

The proposal is to introduce a field picking syntax to select multiple fields from an object in one query. For instance, using the following syntax: $.data.items[*].data.{name, color}. With this, the desired output would be:

[
  { name: 'Apple', color: 'red' },
  { name: 'Banana', color: 'yellow' }
]

This would greatly simplify the process of extracting specific fields from JSON data.

Alternatives considered

An alternative could be to continue using multiple queries or to use a more general query and then process the result. However, this can become cumbersome when dealing with large JSON objects or when needing to extract multiple fields.

@callumgare
Copy link

I would also love this! There is already a syntax that is used by a couple of other parses so I think it makes most sense to use that syntax: https://cburgmer.github.io/json-path-comparison/results/parens_notation.html

@callumgare
Copy link

callumgare commented Jun 27, 2023

Actually it looks like this ticket is a duplicate of #153 so maybe this ticket should be closed and I'll stick my other comment there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants