Greenbone Vulnerability Management Libraries: util/json.h File Reference

Greenbone Vulnerability Management Libraries 23.1.2

Macros | Functions
json.h File Reference
`#include <cjson/cJSON.h>`
`#include <glib.h>`

Go to the source code of this file.

## Macros
#define | _GNU_SOURCE

## Functions
gchar * | gvm_json_string_escape (const char *, gboolean)
| Escapes a string according to the JSON or JSONPath standard.
double | gvm_json_obj_double (cJSON *, const gchar *)
| Get a double field from a JSON object.
int | gvm_json_obj_check_int (cJSON *, const gchar *, int *)
| Get an int field from a JSON object.
int | gvm_json_obj_int (cJSON *, const gchar *)
| Get an int field from a JSON object.
int | gvm_json_obj_check_str (cJSON *, const gchar *, gchar **)
| Get a string field from a JSON object.
gchar * | gvm_json_obj_str (cJSON *, const gchar *)
| Get a string field from a JSON object.

## Macro Definition Documentation

## ◆ _GNU_SOURCE

#define _GNU_SOURCE

## Function Documentation

## ◆ gvm_json_obj_check_int()

int gvm_json_obj_check_int | ( | cJSON * | obj,
|  | const gchar * | key,
|  | int * | val )

Get an int field from a JSON object.

Parameters

  [in] | obj | Object
  [in] | key | Field name.
  [out] | val | Either NULL or a return location for the int (only set if int field exists).

Returns
  0 if such an int field exists, else 1.

## ◆ gvm_json_obj_check_str()

int gvm_json_obj_check_str | ( | cJSON * | obj,
|  | const gchar * | key,
|  | gchar ** | val )

Get a string field from a JSON object.

Parameters

  [in] | obj | Object
  [in] | key | Field name.
  [out] | val | Either NULL or a return location for the string (only set if string field exists). Freed by cJSON_Delete.

Returns
  0 if such a field exists, else 1.

## ◆ gvm_json_obj_double()

double gvm_json_obj_double | ( | cJSON * | obj,
|  | const gchar * | key )

Get a double field from a JSON object.

Parameters

  [in] | obj | Object
  [in] | key | Field name.

Returns
  A double.

## ◆ gvm_json_obj_int()

int gvm_json_obj_int | ( | cJSON * | obj,
|  | const gchar * | key )

Get an int field from a JSON object.

Parameters

  [in] | obj | Object
  [in] | key | Field name.

Returns
  An int.

## ◆ gvm_json_obj_str()

gchar * gvm_json_obj_str | ( | cJSON * | obj,
|  | const gchar * | key )

Get a string field from a JSON object.

Parameters

  [in] | obj | Object
  [in] | key | Field name.

Returns
  A string. Will be freed by cJSON_Delete.

## ◆ gvm_json_string_escape()

gchar * gvm_json_string_escape | ( | const char * | string,
|  | gboolean | single_quote )

Escapes a string according to the JSON or JSONPath standard.

Parameters

  [in] | string | The string to escape
  [in] | single_quote | Whether to escape single quotes

Returns
  The escaped string