Javascript JPath: Difference between revisions

From Yate Documentation
Jump to navigation Jump to search
Marian (talk | contribs)
Created page with "Javascript JPath as specified in RFC 6901. Notes: * Path items separator is slash (/) character * Path may not start with slash (/) character * Escape char is tilde (~). The ..."
 
Marian (talk | contribs)
No edit summary
 
Line 37: Line 37:
Return:<br>
Return:<br>
Path item string (unescaped, may be empty), 'undefined' if index is out of range. Index may be out of range for empty or invalid paths.
Path item string (unescaped, may be empty), 'undefined' if index is out of range. Index may be out of range for empty or invalid paths.
[[Category:Javascript]]

Latest revision as of 10:39, 9 September 2024

Javascript JPath as specified in RFC 6901.

Notes:

  • Path items separator is slash (/) character
  • Path may not start with slash (/) character
  • Escape char is tilde (~). The following characters MUST be escaped in path item names:
    • Tilde (~): ~0
    • Slash (/): ~1

Constructor

  • new JPath(str)

Create a new JPath object.
Parameters:
str: String with JSON path

Methods

  • valid()

Check if path is valid.
Return:
True if path is valid, false otherwise

  • getItems()

Retrieve path item(s).
Return:
Array of strings. Each item contains its unescaped value. Array may be empty for empty or invalid paths

  • count()

Retrieve the number of items in path.
Return:
Number of items in path, 0 if path is empty or invalid

  • at(idx)

Retrieve the path item at given index.
Parameters:
idx: 0 based index to retrieve
Return:
Path item string (unescaped, may be empty), 'undefined' if index is out of range. Index may be out of range for empty or invalid paths.