HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_JSONPath_T< T, FUNC > Class Template Reference

Implement simple JSONPath parser. More...

#include <UT_JSONPath.h>

Static Public Member Functions

static bool find (UT_Set< const T * > &matches, const T &src, const char *expr)
 

Detailed Description

template<typename T, class FUNC>
class UT_JSONPath_T< T, FUNC >

Implement simple JSONPath parser.

This supports a very simple JSONPath syntax:

  • $: root object
  • @, this: current object
  • path: named operator
  • . or []: child operator (path or index)
  • [,]: union operator (union of paths or indices)
  • ..: recursive descent
  • *: wildcard

Limitations:

  • Array slicing is not supported
  • No expression support - you can't do $.book[?(@.cost<7)].title) Extensions:
  • path objects can be regex expressions

As there's no formal syntax for JSONPath, this class was inspired from https://goessner.net/articles/JsonPath/

For example, with the JSON:

{
"animals" : [
{
"type" : "cow",
"legs" : 4,
"wings" : false
},
{
"type" : "cat",
"legs" : 4,
"wings" : false
},
{
"type" : "budgie",
"legs" : 2,
"wings" : true
}
],
"vehicles" : [ ]
}

Paths would resolve:

$.animals[1] -> { "type" : "cat", "legs" : 4, "wings : false }
$.animals[0,1]."type" -> [ "cow", "cat" ]
$[animals].."type" -> [ "cow", "cat", "budgie" ]
$[vehicles] -> [ ]

The template expects a functor class to provide information about the object, which needs to have:

  • static inline bool isArray(const T *obj);
  • static inline bool isMap(const T *obj);
  • static inline const T *arrayItem(const T *obj, exint idx);
  • static inline const T *mapItem(const T *obj, const char *name);
  • static inline iterator arrayBegin(const T &obj);
  • static inline iterator arrayEnd(const T &obj);
  • static inline iterator mapBegin(const T &obj);
  • static inline iterator mapEnd(const T &obj);

Definition at line 90 of file UT_JSONPath.h.

Member Function Documentation

template<typename T , class FUNC >
static bool UT_JSONPath_T< T, FUNC >::find ( UT_Set< const T * > &  matches,
const T src,
const char *  expr 
)
inlinestatic

Definition at line 93 of file UT_JSONPath.h.


The documentation for this class was generated from the following file: