Skip to content

error loc.indexOf is not a function #181

Open

Description

@thboileau

Describe the bug

I get this error with a specific expression: loc.indexOf is not a function

Code sample or steps to reproduce

Given this json payload:

{
  "stores": [
    { "name": "Store 1"},
    { "name": "Store 2" },
    { "name": "Store 3" },
    { "name": "Store 4"}
  ]
}

When I apply this path $.stores[1:4:2][(@.length-1)].name
Then I get an error: loc.indexOf is not a function.

Please note that this expression ($.stores[1:4:2]) returns:

[
  { "name": "Store 2" },
  { "name": "Store 4" }
]

And this expression ($.stores[(@.length-1)].name) returns:

[
  "Store 4"
]

Expected behavior

There should be no error.

Expected result

"Store 4"

Environment (IMPORTANT)

  • JSONPath-Plus version: 7.2.0

Desktop**

  • OS: Linux Ubuntu 20.04
  • Browser Chrome, version 107.0.5304.87

Activity

  1. TrurlMcByte commented on Nov 24, 2022

    @TrurlMcByte

    Getting the same error on deleting an element from an array inside callback. But splice solve it.

  2. 80avin commented on Feb 15, 2025

    @80avin
    Collaborator

    I can confirm this.
    It happens in this path

    $.stores[1:4:2][(@.length-1)].name
    

    but not in this path

    $.stores[(@.length-1)].name
    

    Using regular expressions for parsing paths is not a good idea. I am working on building a parser for the path expressions, which will fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions