Skip to content

Getting bracket-notated children error #174

Open

Description

@oleg-gr

Given this JSON object

{
  "object": {
    "0":"0",
    "1":"1",
    "2":"2",
  }
}

Trying to run

Configuration configuration = Configuration.defaultConfiguration().jsonProvider(new JacksonJsonNodeJsonProvider()).mappingProvider(new JacksonMappingProvider()).addOptions(Option.AS_PATH_LIST);
DocumentContext context = JsonPath.parse(JSON_NODE, configuration);
context.read("$.object['0', '1']")

will return [ "[$['object']['0', '1']]" ].

I believe the result should be [ "[$['object']['0']]", "[$['object']['1']]" ]

Activity

  1. kallestenflo commented on Dec 17, 2015

    @kallestenflo
    Contributor

    Running with the AS_PATH_LIST option should return the same number or results as running whitout.

  2. oleg-gr commented on Dec 20, 2015

    @oleg-gr
    Author

    Isn't the call supposed to return the leaves only? It shouldn't return ['0','1'] like that, but ['0'] and ['1']

  3. oleg-gr commented on Jan 7, 2016

    @oleg-gr
    Author

    @kallestenflo Hi, any update on this issue?

  4. oleg-gr commented on Jan 7, 2016

    @oleg-gr
    Author

    Ok, one more argument towards why the returned value should be [ "[$['object']['0']]", "[$['object']['1']]" ] and not [ "[$['object']['0', '1']]" ]

    Consider

    {
      "object": {
        "0":"0",
        "1": {
          "3":"4"
         },
        "2": {
          "3":"4"
         }
      }
    }
    

    Then do

    Configuration configuration = Configuration.defaultConfiguration().jsonProvider(new JacksonJsonNodeJsonProvider()).mappingProvider(new JacksonMappingProvider()).addOptions(Option.AS_PATH_LIST);
    DocumentContext context = JsonPath.parse(JSON_NODE, configuration);
    context.read("$.object['1', '2'].3")
    

    and as of current implementation of this library the returned paths will be [ "[$['object']['1']['3']]", "[$['object']['2']['3']]" ] and not [ "[$['object']['1', '2']['3']]" ]. I think this is inconsistent behaviour

  5. jochenberger commented on Feb 19, 2016

    @jochenberger
    Contributor

    The Jayway, Gatling and Goessner implementations have very different opinions about that one:
    Jayway:

    {
       "0" : "0",
       "1" : "1"
    }
    

    Gatling:

    [
       "0",
       "1"
    ]
    

    Goessner:

    [
       "0"
    ]
    

    I think I'm with @oleg-gr and Gatling on this one. The result should not include the property keys.

  6. kallestenflo commented on Feb 19, 2016

    @kallestenflo
    Contributor

    I agree the current behavior is strange. It should work the same way as when multiple array indexes are specified.

    $.array[1, 2].3 evaluates the same way as $.object['1', '2'].3

  7. kallestenflo commented on Feb 19, 2016

    @kallestenflo
    Contributor

    I think this should wait until 3.0

  8. added this to the 3.0 milestone on Feb 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions