[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 568
  • Last Modified:

JSONPAth expression tester

I am reading about JSONPath script from th efollowing site

http://goessner.net/articles/JsonPath/

Open in new window


So I went to the JSON tester site

http://jsonpath.curiousconcept.com/

Open in new window


and entered the following into the JSON Data seciont

{ "identification" : "AlphaBeta" }

Open in new window


Then I entered the following into the JSON Expression section:

$.identification

Open in new window


That resulted in the following in the 'Results' section:

[
   "AlphaBeta"
]

Open in new window


My question:  Why does it place a begining bracket '[', and a closing bracket '].

Why doesnt it just report the following:

   "AlphaBeta"

Open in new window

0
Anthony Lucia
Asked:
Anthony Lucia
  • 2
1 Solution
 
Alexandre SimõesManager / Technology SpecialistCommented:
I'm no expert on that jsonPath but it seems like the result can be a set of matches.
I mean, your "query" can have multiple result, that's why the result is a collection.
0
 
Alexandre SimõesManager / Technology SpecialistCommented:
Although you don't need to use fancy libraries for this specific case you're doing.
For your JSON object you can simply do:
var json = { "identification" : "AlphaBeta" };

// get identification
var option1 = json.identification;    // returns: AlphaBeta
var option2 = json['identification']; // returns: AlphaBeta

// if you ask for a property that doesn't exist you'll get undefined
var option1 = json.name;    // returns: undefined
var option2 = json['name']; // returns: undefined

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now