Fledge
An open source edge computing platform for industrial users
JSONPath.h
1 /*
2  * Fledge RapaidJSON JSONPath search helper
3  *
4  * Copyright (c) 2020 Dianomic Systems
5  *
6  * Released under the Apache 2.0 Licence
7  *
8  * Author: Mark Riddoch
9  */
10 #ifndef _JSONPATH_H
11 #define _JSONPATH_H
12 
13 #include <rapidjson/document.h>
14 #include <string>
15 #include <vector>
16 #include <logger.h>
17 
22 class JSONPath {
23  public:
24  JSONPath(const std::string& path);
25  ~JSONPath();
26  rapidjson::Value *findNode(rapidjson::Value& root);
27  private:
28  class PathComponent {
29  public:
30  virtual rapidjson::Value *match(rapidjson::Value *node) = 0;
31  };
32  class LiteralPathComponent : public PathComponent {
33  public:
34  LiteralPathComponent(std::string& name);
35  rapidjson::Value *match(rapidjson::Value *node);
36  private:
37  std::string m_name;
38  };
39  class IndexPathComponent : public PathComponent {
40  public:
41  IndexPathComponent(std::string& name, int index);
42  rapidjson::Value *match(rapidjson::Value *node);
43  private:
44  std::string m_name;
45  int m_index;
46  };
47  class MatchPathComponent : public PathComponent {
48  public:
49  MatchPathComponent(std::string& name, std::string& property, std::string& value);
50  rapidjson::Value *match(rapidjson::Value *node);
51  private:
52  std::string m_name;
53  std::string m_property;
54  std::string m_value;
55  };
56  void parse();
57  std::string m_path;
58  std::vector<PathComponent *>
59  m_parsed;
60  Logger *m_logger;
61 };
62 
63 #endif
Fledge Logger class used to log to syslog.
Definition: logger.h:26
A simple implementation of a JSON Path search mechanism to use alongside RapidJSON.
Definition: JSONPath.h:22
rapidjson::Value * findNode(rapidjson::Value &root)
Find the matching node in the JSON document.
Definition: JSONPath.cpp:39
~JSONPath()
Destructor for the JSONPath.
Definition: JSONPath.cpp:28