Search code examples
javajsonpathjayway

Any reason to start a JsonPath without the "$" dollar sign?


In JsonPath, I've seen the "$" sign described as the symbol that "refers to the root object or element".

Example:

JsonPath.read(json, "$.store.book[*].author");

Question: is there any reason not to start the path with "$"?

In Jayway, you can omit the "$." at the start of a path and get the same result.

But, is there any reason to do this?


Solution

  • In Smartbear.com's JSON documentation they point out:

    The leading $ represents the root object or array and can be omitted. For example, $.foo.bar and foo.bar are the same, and so are $[0].status and [0].status.

    The full document can be viewed here.

    So looks like the $ sign is simply there for style, which leads to the question of why the JSONPath creators implemented it.