Go to the documentation of this file.
28 #ifndef CPL_JSON_H_INCLUDED
29 #define CPL_JSON_H_INCLUDED
31 #include "cpl_progress.h"
44 typedef void *JSONObjectH;
109 explicit CPLJSONObject(
const std::string &osName, JSONObjectH poJsonObject);
114 void Add(
const std::string &osName,
const std::string &osValue);
115 void Add(
const std::string &osName,
const char *pszValue);
116 void Add(
const std::string &osName,
double dfValue);
117 void Add(
const std::string &osName,
int nValue);
118 void Add(
const std::string &osName,
GInt64 nValue);
119 void Add(
const std::string &osName, uint64_t nValue);
120 void Add(
const std::string &osName,
const CPLJSONArray &oValue);
121 void Add(
const std::string &osName,
const CPLJSONObject &oValue);
122 void AddNoSplitName(
const std::string &osName,
const CPLJSONObject &oValue);
123 void Add(
const std::string &osName,
bool bValue);
124 void AddNull(
const std::string &osName);
126 void Set(
const std::string &osName,
const std::string &osValue);
127 void Set(
const std::string &osName,
const char *pszValue);
128 void Set(
const std::string &osName,
double dfValue);
129 void Set(
const std::string &osName,
int nValue);
130 void Set(
const std::string &osName,
GInt64 nValue);
131 void Set(
const std::string &osName, uint64_t nValue);
132 void Set(
const std::string &osName,
bool bValue);
133 void SetNull(
const std::string &osName);
136 JSONObjectH GetInternalHandle()
const
138 return m_poJsonObject;
143 std::string GetString(
const std::string &osName,
144 const std::string &osDefault =
"")
const;
145 double GetDouble(
const std::string &osName,
double dfDefault = 0.0)
const;
146 int GetInteger(
const std::string &osName,
int nDefault = 0)
const;
147 GInt64 GetLong(
const std::string &osName,
GInt64 nDefault = 0)
const;
148 bool GetBool(
const std::string &osName,
bool bDefault =
false)
const;
149 std::string ToString(
const std::string &osDefault =
"")
const;
150 double ToDouble(
double dfDefault = 0.0)
const;
151 int ToInteger(
int nDefault = 0)
const;
153 bool ToBool(
bool bDefault =
false)
const;
155 std::string Format(PrettyFormat eFormat)
const;
158 void Delete(
const std::string &osName);
159 void DeleteNoSplitName(
const std::string &osName);
163 Type GetType()
const;
165 std::string GetName()
const
171 std::vector<CPLJSONObject> GetChildren()
const;
172 bool IsValid()
const;
178 std::string &osName)
const;
182 JSONObjectH m_poJsonObject =
nullptr;
183 std::string m_osKey{};
201 explicit CPLJSONArray(
const std::string &osName, JSONObjectH poJsonObject);
203 class CPL_DLL ConstIterator
211 : m_oSelf(oSelf), m_nIdx(bStart ? 0 : oSelf.
Size())
214 ~ConstIterator() =
default;
217 m_oObj = m_oSelf[m_nIdx];
220 ConstIterator &operator++()
225 bool operator==(
const ConstIterator &it)
const
227 return m_nIdx == it.m_nIdx;
229 bool operator!=(
const ConstIterator &it)
const
231 return m_nIdx != it.m_nIdx;
240 void Add(
const std::string &osValue);
241 void Add(
const char *pszValue);
242 void Add(
double dfValue);
243 void Add(
int nValue);
245 void Add(uint64_t nValue);
246 void Add(
bool bValue);
253 return ConstIterator(*
this,
true);
258 return ConstIterator(*
this,
false);
277 bool Save(
const std::string &osPath)
const;
278 std::string SaveAsString()
const;
283 bool Load(
const std::string &osPath);
284 bool LoadMemory(
const std::string &osStr);
285 bool LoadMemory(
const GByte *pabyData,
int nLength = -1);
286 bool LoadChunks(
const std::string &osPath,
size_t nChunkSize = 16384,
287 GDALProgressFunc pfnProgress =
nullptr,
288 void *pProgressArg =
nullptr);
289 bool LoadUrl(
const std::string &osUrl,
const char *
const *papszOptions,
290 GDALProgressFunc pfnProgress =
nullptr,
291 void *pProgressArg =
nullptr);
294 mutable JSONObjectH m_poRootJsonObject;
299 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
306 #endif // CPL_JSON_H_INCLUDED
The JSONArray class JSON array from JSONDocument.
Definition: cpl_json.h:189
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:196
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:437
CPLStringList CPLParseKeyValueJson(const char *pszJson)
Return a string list of key/value pairs extracted from a JSON doc.
Definition: cpl_json.cpp:1629
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:247
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:306
PrettyFormat
Json object format to string options.
Definition: cpl_json.h:79
The CPLJSONArray class holds JSON object from CPLJSONDocument.
Definition: cpl_json.h:54
ConstIterator end() const
Iterator to after last element.
Definition: cpl_json.h:256
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:310
Type
Json object types.
Definition: cpl_json.h:63
int Size() const
Get array size.
Definition: cpl_json.cpp:1452
ConstIterator begin() const
Iterator to first element.
Definition: cpl_json.h:251
The CPLJSONDocument class Wrapper class around json-c library.
Definition: cpl_json.h:265