GDAL

Public Types | Public Member Functions | Friends | List of all members
CPLJSONArray Class Reference

The JSONArray class JSON array from JSONDocument. More...

`#include <cpl_json.h>`

Inheritance diagram for CPLJSONArray:

## Public Types
enum class | Type { Unknown , Null , Object , Array , Boolean , String , Integer , Long , Double }
| Json object types.
enum class | PrettyFormat { Plain , Spaced , Pretty }
| Json object format to string options. More...

## Public Member Functions
int | Size () const
| Get array size.
void | AddNull ()
| Add null object to array.
void | Add (const CPLJSONObject &oValue)
| Add json object to array.
void | Add (const std::string &osValue)
| Add value to array.
void | Add (const char *pszValue)
| Add value to array.
void | Add (double dfValue)
| Add value to array.
void | Add (int nValue)
| Add value to array.
void | Add (GInt64 nValue)
| Add value to array.
void | Add (uint64_t nValue)
| Add value to array.
void | Add (bool bValue)
| Add value to array.
CPLJSONObject | operator[] (int nIndex)
| Get array item by index.
const CPLJSONObject | operator[] (int nIndex) const
| Get array const item by index.
ConstIterator | begin () const
| Iterator to first element.
ConstIterator | end () const
| Iterator to after last element.
void | Add (const std::string &osName, const std::string &osValue)
| Add new key - value pair to json object.
void | Add (const std::string &osName, const char *pszValue)
| Add new key - value pair to json object.
void | Add (const std::string &osName, double dfValue)
| Add new key - value pair to json object.
void | Add (const std::string &osName, int nValue)
| Add new key - value pair to json object.
void | Add (const std::string &osName, GInt64 nValue)
| Add new key - value pair to json object.
void | Add (const std::string &osName, uint64_t nValue)
| Add new key - value pair to json object.
void | Add (const std::string &osName, const CPLJSONArray &oValue)
| Add new key - value pair to json object.
void | Add (const std::string &osName, const CPLJSONObject &oValue)
| Add new key - value pair to json object.
void | Add (const std::string &osName, bool bValue)
| Add new key - value pair to json object.
void | AddNoSplitName (const std::string &osName, const CPLJSONObject &oValue)
| Add new key - value pair to json object.
void | AddNull (const std::string &osName)
| Add new key - null pair to json object.
void | Set (const std::string &osName, const std::string &osValue)
| Change value by key.
void | Set (const std::string &osName, const char *pszValue)
| Change value by key.
void | Set (const std::string &osName, double dfValue)
| Change value by key.
void | Set (const std::string &osName, int nValue)
| Change value by key.
void | Set (const std::string &osName, GInt64 nValue)
| Change value by key.
void | Set (const std::string &osName, uint64_t nValue)
| Change value by key.
void | Set (const std::string &osName, bool bValue)
| Change value by key.
void | SetNull (const std::string &osName)
| Change value by key.
std::string | GetString (const std::string &osName, const std::string &osDefault="") const
| Get value by key.
double | GetDouble (const std::string &osName, double dfDefault=0.0) const
| Get value by key.
int | GetInteger (const std::string &osName, int nDefault=0) const
| Get value by key.
GInt64 | GetLong (const std::string &osName, GInt64 nDefault=0) const
| Get value by key.
bool | GetBool (const std::string &osName, bool bDefault=false) const
| Get value by key.
std::string | ToString (const std::string &osDefault="") const
| Get value.
double | ToDouble (double dfDefault=0.0) const
| Get value.
int | ToInteger (int nDefault=0) const
| Get value.
GInt64 | ToLong (GInt64 nDefault=0) const
| Get value.
bool | ToBool (bool bDefault=false) const
| Get value.
CPLJSONArray | ToArray () const
| Get value.
std::string | Format (PrettyFormat eFormat) const
| Stringify object to json format.
void | Delete (const std::string &osName)
| Delete json object by key.
void | DeleteNoSplitName (const std::string &osName)
| Delete json object by key (without splitting on /)
CPLJSONArray | GetArray (const std::string &osName) const
| Get value by key.
CPLJSONObject | GetObj (const std::string &osName) const
| Get value by key.
CPLJSONObject | operator[] (const std::string &osName) const
| Get value by key.
Type | GetType () const
| Get json object type.
std::vector< CPLJSONObject > | GetChildren () const
| Get json object children.
bool | IsValid () const
| Check if json object valid.
void | Deinit ()
| Decrement reference counter and make pointer NULL.

## Friends
class | CPLJSONObject
class | CPLJSONDocument

## Detailed Description

The JSONArray class JSON array from JSONDocument.

## Member Enumeration Documentation

## ◆ PrettyFormat

enum class CPLJSONObject::PrettyFormat
| strong inherited

Json object format to string options.

Enumerator
Plain | No extra whitespace or formatting applied.
Spaced | Minimal whitespace inserted.
Pretty | Formatted output.

## Member Function Documentation

## ◆ Add() [1/17]

void CPLJSONArray::Add | ( | bool | bValue | ) |

Add value to array.

Parameters

  bValue | Value to add.

Since
  GDAL 2.3

## ◆ Add() [2/17]

void CPLJSONArray::Add | ( | const char * | pszValue | ) |

Add value to array.

Parameters

  pszValue | Value to add.

Since
  GDAL 2.3

## ◆ Add() [3/17]

void CPLJSONArray::Add | ( | const CPLJSONObject & | oValue | ) |

Add json object to array.

Parameters

  oValue | Json array.

Since
  GDAL 2.3

## ◆ Add() [4/17]

void CPLJSONObject::Add | ( | const std::string & | osName,
|  | bool | bValue
| ) |  |
| inherited

Add new key - value pair to json object.

Parameters

  osName | Key name.
  bValue | Boolean value.

Since
  GDAL 2.3

## ◆ Add() [5/17]

void CPLJSONObject::Add | ( | const std::string & | osName,
|  | const char * | pszValue
| ) |  |
| inherited

Add new key - value pair to json object.

Parameters

  osName | Key name.
  pszValue | String value.

Since
  GDAL 2.3

## ◆ Add() [6/17]

void CPLJSONObject::Add | ( | const std::string & | osName,
|  | const CPLJSONArray & | oValue
| ) |  |
| inherited

Add new key - value pair to json object.

Parameters

  osName | Key name.
  oValue | Array value.

Since
  GDAL 2.3

## ◆ Add() [7/17]

void CPLJSONObject::Add | ( | const std::string & | osName,
|  | const CPLJSONObject & | oValue
| ) |  |
| inherited

Add new key - value pair to json object.

Parameters

  osName | Key name.
  oValue | Json object value.

Since
  GDAL 2.3

## ◆ Add() [8/17]

void CPLJSONObject::Add | ( | const std::string & | osName,
|  | const std::string & | osValue
| ) |  |
| inherited

Add new key - value pair to json object.

Parameters

  osName | Key name.
  osValue | String value.

Since
  GDAL 2.3

## ◆ Add() [9/17]

void CPLJSONObject::Add | ( | const std::string & | osName,
|  | double | dfValue
| ) |  |
| inherited

Add new key - value pair to json object.

Parameters

  osName | Key name.
  dfValue | Double value.

Since
  GDAL 2.3

## ◆ Add() [10/17]

void CPLJSONObject::Add | ( | const std::string & | osName,
|  | GInt64 | nValue
| ) |  |
| inherited

Add new key - value pair to json object.

Parameters

  osName | Key name.
  nValue | Long value.

Since
  GDAL 2.3

## ◆ Add() [11/17]

void CPLJSONObject::Add | ( | const std::string & | osName,
|  | int | nValue
| ) |  |
| inherited

Add new key - value pair to json object.

Parameters

  osName | Key name.
  nValue | Integer value.

Since
  GDAL 2.3

## ◆ Add() [12/17]

void CPLJSONObject::Add | ( | const std::string & | osName,
|  | uint64_t | nValue
| ) |  |
| inherited

Add new key - value pair to json object.

Parameters

  osName | Key name.
  nValue | uint64_t value.

Since
  GDAL 3.8

## ◆ Add() [13/17]

void CPLJSONArray::Add | ( | const std::string & | osValue | ) |

Add value to array.

Parameters

  osValue | Value to add.

Since
  GDAL 2.3

## ◆ Add() [14/17]

void CPLJSONArray::Add | ( | double | dfValue | ) |

Add value to array.

Parameters

  dfValue | Value to add.

Since
  GDAL 2.3

## ◆ Add() [15/17]

void CPLJSONArray::Add | ( | GInt64 | nValue | ) |

Add value to array.

Parameters

  nValue | Value to add.

Since
  GDAL 2.3

## ◆ Add() [16/17]

void CPLJSONArray::Add | ( | int | nValue | ) |

Add value to array.

Parameters

  nValue | Value to add.

Since
  GDAL 2.3

## ◆ Add() [17/17]

void CPLJSONArray::Add | ( | uint64_t | nValue | ) |

Add value to array.

Parameters

  nValue | Value to add.

Since
  GDAL 3.8

## ◆ AddNoSplitName()

void CPLJSONObject::AddNoSplitName | ( | const std::string & | osName,
|  | const CPLJSONObject & | oValue
| ) |  |
| inherited

Add new key - value pair to json object.

Parameters

  osName | Key name (do not split it on '/')
  oValue | Json object value.

Since
  GDAL 3.2

## ◆ AddNull() [1/2]

void CPLJSONArray::AddNull | ( |  | ) |

Add null object to array.

Since
  GDAL 3.8

## ◆ AddNull() [2/2]

void CPLJSONObject::AddNull | ( | const std::string & | osName | ) |
| inherited

Add new key - null pair to json object.

Parameters

  osName | Key name.

Since
  GDAL 2.3

## ◆ Deinit()

void CPLJSONObject::Deinit | ( |  | ) |
| inherited

Decrement reference counter and make pointer NULL.

A json object will become invalid.

Since
  GDAL 2.3

## ◆ Delete()

void CPLJSONObject::Delete | ( | const std::string & | osName | ) |
| inherited

Delete json object by key.

Parameters

  osName | Key name.

Since
  GDAL 2.3

## ◆ DeleteNoSplitName()

void CPLJSONObject::DeleteNoSplitName | ( | const std::string & | osName | ) |
| inherited

Delete json object by key (without splitting on /)

Parameters

  osName | Key name.

Since
  GDAL 3.4

## ◆ Format()

std::string CPLJSONObject::Format | ( | PrettyFormat | eFormat | ) | const
| inherited

Stringify object to json format.

Parameters

  eFormat | Format type,

Returns
  A string in JSON format.

Since
  GDAL 2.3

## ◆ GetArray()

CPLJSONArray CPLJSONObject::GetArray | ( | const std::string & | osName | ) | const
| inherited

Get value by key.

Parameters

  osName | Key name.

Returns
  Json array object.

Since
  GDAL 2.3

## ◆ GetBool()

bool CPLJSONObject::GetBool | ( | const std::string & | osName,
|  | bool | bDefault = `false`
| ) |  | const
| inherited

Get value by key.

Parameters

  osName | Key name.
  bDefault | Default value.

Returns
  Boolean value.

Since
  GDAL 2.3

## ◆ GetChildren()

std::vector< CPLJSONObject > CPLJSONObject::GetChildren | ( |  | ) | const
| inherited

Get json object children.

This function is useful when keys is not know and need to iterate over json object items and get keys and values.

Returns
  Array of CPLJSONObject class instance.

Since
  GDAL 2.3

## ◆ GetDouble()

double CPLJSONObject::GetDouble | ( | const std::string & | osName,
|  | double | dfDefault = `0.0`
| ) |  | const
| inherited

Get value by key.

Parameters

  osName | Key name.
  dfDefault | Default value.

Returns
  Double value.

Since
  GDAL 2.3

## ◆ GetInteger()

int CPLJSONObject::GetInteger | ( | const std::string & | osName,
|  | int | nDefault = `0`
| ) |  | const
| inherited

Get value by key.

Parameters

  osName | Key name.
  nDefault | Default value.

Returns
  Integer value.

Since
  GDAL 2.3

## ◆ GetLong()

GInt64 CPLJSONObject::GetLong | ( | const std::string & | osName,
|  | GInt64 | nDefault = `0`
| ) |  | const
| inherited

Get value by key.

Parameters

  osName | Key name.
  nDefault | Default value.

Returns
  Long value.

Since
  GDAL 2.3

## ◆ GetObj()

CPLJSONObject CPLJSONObject::GetObj | ( | const std::string & | osName | ) | const
| inherited

Get value by key.

Parameters

  osName | Key name.

Returns
  Json object.

Since
  GDAL 2.3

## ◆ GetString()

std::string CPLJSONObject::GetString | ( | const std::string & | osName,
|  | const std::string & | osDefault = `""`
| ) |  | const
| inherited

Get value by key.

Parameters

  osName | Key name.
  osDefault | Default value.

Returns
  String value.

Since
  GDAL 2.3

## ◆ GetType()

CPLJSONObject::Type CPLJSONObject::GetType | ( |  | ) | const
| inherited

Get json object type.

Returns
  Json object type.

Since
  GDAL 2.3

## ◆ IsValid()

bool CPLJSONObject::IsValid | ( |  | ) | const
| inherited

Check if json object valid.

Returns
  true if json object valid.

Since
  GDAL 2.3

## ◆ operator[]() [1/3]

CPLJSONObject CPLJSONObject::operator[] | ( | const std::string & | osName | ) | const
| inherited

Get value by key.

Parameters

  osName | Key name.

Returns
  Json object.

Since
  GDAL 2.3

## ◆ operator[]() [2/3]

CPLJSONObject CPLJSONArray::operator[] | ( | int | nIndex | ) |

Get array item by index.

Parameters

  nIndex | Item index.

Returns
  Json object.

Since
  GDAL 2.3

## ◆ operator[]() [3/3]

const CPLJSONObject CPLJSONArray::operator[] | ( | int | nIndex | ) | const

Get array const item by index.

Parameters

  nIndex | Item index.

Returns
  Json object.

Since
  GDAL 2.3

## ◆ Set() [1/7]

void CPLJSONObject::Set | ( | const std::string & | osName,
|  | bool | bValue
| ) |  |
| inherited

Change value by key.

Parameters

  osName | Key name.
  bValue | Boolean value.

Since
  GDAL 2.3

## ◆ Set() [2/7]

void CPLJSONObject::Set | ( | const std::string & | osName,
|  | const char * | pszValue
| ) |  |
| inherited

Change value by key.

Parameters

  osName | Key name.
  pszValue | String value.

Since
  GDAL 2.3

## ◆ Set() [3/7]

void CPLJSONObject::Set | ( | const std::string & | osName,
|  | const std::string & | osValue
| ) |  |
| inherited

Change value by key.

Parameters

  osName | Key name.
  osValue | String value.

Since
  GDAL 2.3

## ◆ Set() [4/7]

void CPLJSONObject::Set | ( | const std::string & | osName,
|  | double | dfValue
| ) |  |
| inherited

Change value by key.

Parameters

  osName | Key name.
  dfValue | Double value.

Since
  GDAL 2.3

## ◆ Set() [5/7]

void CPLJSONObject::Set | ( | const std::string & | osName,
|  | GInt64 | nValue
| ) |  |
| inherited

Change value by key.

Parameters

  osName | Key name.
  nValue | Long value.

Since
  GDAL 2.3

## ◆ Set() [6/7]

void CPLJSONObject::Set | ( | const std::string & | osName,
|  | int | nValue
| ) |  |
| inherited

Change value by key.

Parameters

  osName | Key name.
  nValue | Integer value.

Since
  GDAL 2.3

## ◆ Set() [7/7]

void CPLJSONObject::Set | ( | const std::string & | osName,
|  | uint64_t | nValue
| ) |  |
| inherited

Change value by key.

Parameters

  osName | Key name.
  nValue | uint64_t value.

Since
  GDAL 3.8

## ◆ SetNull()

void CPLJSONObject::SetNull | ( | const std::string & | osName | ) |
| inherited

Change value by key.

Parameters

  osName | Key name.

Since
  GDAL 2.3

## ◆ Size()

int CPLJSONArray::Size | ( |  | ) | const

Get array size.

Returns
  Array size.

Since
  GDAL 2.3

## ◆ ToArray()

CPLJSONArray CPLJSONObject::ToArray | ( |  | ) | const
| inherited

Get value.

Returns
  Array

Since
  GDAL 2.3

## ◆ ToBool()

bool CPLJSONObject::ToBool | ( | bool | bDefault = `false` | ) | const
| inherited

Get value.

Parameters

  bDefault | Default value.

Returns
  Boolean value.

Since
  GDAL 2.3

## ◆ ToDouble()

double CPLJSONObject::ToDouble | ( | double | dfDefault = `0.0` | ) | const
| inherited

Get value.

Parameters

  dfDefault | Default value.

Returns
  Double value.

Since
  GDAL 2.3

## ◆ ToInteger()

int CPLJSONObject::ToInteger | ( | int | nDefault = `0` | ) | const
| inherited

Get value.

Parameters

  nDefault | Default value.

Returns
  Integer value.

Since
  GDAL 2.3

## ◆ ToLong()

GInt64 CPLJSONObject::ToLong | ( | GInt64 | nDefault = `0` | ) | const
| inherited

Get value.

Parameters

  nDefault | Default value.

Returns
  Long value.

Since
  GDAL 2.3

## ◆ ToString()

std::string CPLJSONObject::ToString | ( | const std::string & | osDefault = `""` | ) | const
| inherited

Get value.

Parameters

  osDefault | Default value.

Returns
  String value.

Since
  GDAL 2.3

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

- cpl_json.h
- cpl_json.cpp