GetElementByPointer method (NotesJSONNavigator – LotusScript)

Retrieves a NotesJSONElement using JSON Pointer syntax to identify the element.

Defined in

NotesJSONNavigator

Syntax

Set el = jsnav.GetElementByPointer(pointer)

Parameters

pointer

String. String in JSON Pointer notation.

A JSON Pointer is string that identifies the desired element. This JSON Pointer is a list of zero-to-many tokens, each prefixed by "/". Each token can be a string or a number.

Compared to using GetElementByName the JSON Pointer syntax used by GetElementByPointer can simplify working with more complex JSON objects.

For example, given a JSON:

{
"fruit" : ["apple", "banana"],
"price" : 1.99
}

The following JSON Pointers resolve this JSON as:

I. "/fruit" → [ "apple", "banana" ]

II. "/fruit/0" → "apple"

III. "/fruit/1" → "banana"

IV. "/price" → 1.99

Note that, an empty JSON Pointer "" (zero token) resolves to the whole JSON.

[SuppressErrors]
Boolean. Optional. If True, suppress “JSON Element not found error” and return Null element when element not found.
Note: This parameter is new with release 14.5.1.

Return value

Returns NotesJSONElement that corresponds to the JSON pointer. If pointer is empty string, return whole document in JSONNavigator.

Example

The following code returns an element with name test and value "A string".
Dim jsnav As NotesJSONNavigator
Set jsnav = session.CreateJSONNavigator(|{"test":"A string"}|)
Set el = jsnav.GetElementByPointer("/test")
The following code with suppress error “Element not found” when no element found
Dim jsnav As NotesJSONNavigator
Set jsnav = session.CreateJSONNavigator(|{"test":"A string"}|)
Set el = jsnav.Getelementbypointer("/test1", True)
If el Is Nothing Then
    MessageBox("Elemenet not found")
End If
The following return whole document to element when pass in pointer as empty string.
Dim session As New NotesSession
Dim jsnav As NotesJSONNavigator
Dim el As NotesJSONElement
Dim subel As NotesJSONElement   

Set jsnav = session.CreateJSONNavigator(|{"test1":"A string 1", "test2":"A String2"}|)
Set el = jsnav.GetElementByPointer("") 'Element value now {"test1":"A string 1", "test2":"A String2"}

Set subel = el.value.GetFirstElement()
while Not (subel is Nothing)
    MessageBox(subel.value)
    Set subel = el.value.GetNextElement()
Wend
The following code shows how to use pointer with number, it will return element with value “banana”
Sub Initialize
    Dim session As New NotesSession
    Dim el As NotesJSONElement
    Dim jsnav As NotesJSONNavigator
    Set jsnav = session.CreateJSONNavigator(|{"fruit" : ["apple", "banana"],"price" : 1.99}|)
    Set el = jsnav.GetElementByPointer("/fruit/1") 'banana
    MessageBox(el.value)
End Sub