question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSONPath scripts not executing correctly for objects

See original GitHub issue

Using scripts to query objects does not seem to work properly (although it does work properly for arrays). Given an example JSON:

{
  "A": {
  },
  "B": {
    "B1": 1,
    "B2": 2
  },
  "C": {
    "C1": {
      "C11": true
    },
    "C2": 2
  }
}

Parsing this into a JObject and then executing SelectTokens with a script does not yield the correct results Running $[?(@)] from the root returns the all of the properties in the object, as expected Running $[?(@.B1)] or $[?(@.B1 == 1)] should return the B property, but does not actually If I use the recursive operator, $[?(@..B1)] then the B node is returned, which makes me think that the child operator is not working for a script inside an object.

Additionally, the value of the properties cannot be accessed from within the script. If I run $[?(@ == 1)] inside the B object, I’d like to be returned the B1 token (or the token for its value) but it actually returns nothing.

The behavior that I’m referring to is based on the interpretation of the JSONPath spec expressions as well as the behavior of some JSONPath evaluators such as this and this) The examples that I mentioned above using JSON.Net can he found here.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:12
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
miminnocommented, Feb 10, 2020

That’s a real bummer. Just ran into this issue myself and was surprised to see it’s been left with no attention for almost three years now 😦

4reactions
davilimapcommented, Mar 24, 2017

The spec says that “expressions of the underlying script language can be used as an alternative to explicit names or indices”, which makes me think that filter expressions can also be used instead of names.

Read more comments on GitHub >

github_iconTop Results From Across the Web

json path expression not working without array
See Issue #1256: JSONPath scripts not executing correctly for objects. It comes up here from time to time, e.g. What's the correct JsonPath ......
Read more >
My workflow works on it's own but doesn't when called from ...
When I try to call this script from another script I keep getting an error about not being able to deserialize the current...
Read more >
Solve common issues with JSON in SQL Server
Question. I want to create a JSON text result from a simple SQL query on a single table. FOR JSON PATH and FOR...
Read more >
Working with JSON - Learn web development | MDN
In this article, we've given you a simple guide to using JSON in your programs, including how to create and parse JSON, and...
Read more >
What Is JSON and How to Handle an “Unexpected Token” ...
Learn what JSON is and how you can deal with errors occurring when parsing JSON data, such as "Unexpected Token < in JSON...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found