3 * JSON parsing functions.
5 * Copyright 2016, Dario Lombardo
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include "ws_symbol_export.h"
29 * Check if a buffer is json an returns true if it is.
31 WS_DLL_PUBLIC
bool json_validate(const uint8_t *buf
, const size_t len
);
33 WS_DLL_PUBLIC
int json_parse(const char *buf
, jsmntok_t
*tokens
, unsigned int max_tokens
);
36 * Get the pointer to an object belonging to parent object and named as the name variable.
37 * Returns NULL if not found.
39 WS_DLL_PUBLIC jsmntok_t
*json_get_object(const char *buf
, jsmntok_t
*parent
, const char *name
);
42 * Get the pointer to an array belonging to parent object and named as the name variable.
43 * Returns NULL if not found.
45 WS_DLL_PUBLIC jsmntok_t
*json_get_array(const char *buf
, jsmntok_t
*parent
, const char *name
);
48 * Get the number of elements of an array.
49 * Returns -1 if the JSON objecct is not an array.
51 WS_DLL_PUBLIC
int json_get_array_len(jsmntok_t
*array
);
54 * Get the pointer to idx element of an array.
55 * Returns NULL if not found.
57 WS_DLL_PUBLIC jsmntok_t
*json_get_array_index(jsmntok_t
*parent
, int idx
);
60 * Get the unescaped value of a string object belonging to parent object and named as the name variable.
61 * Returns NULL if not found. Caution: it modifies input buffer.
63 WS_DLL_PUBLIC
char *json_get_string(char *buf
, jsmntok_t
*parent
, const char *name
);
66 * Get the value of a number object belonging to parent object and named as the name variable.
67 * Returns false if not found. Caution: it modifies input buffer.
68 * Scientific notation not supported yet.
70 WS_DLL_PUBLIC
bool json_get_double(char *buf
, jsmntok_t
*parent
, const char *name
, double *val
);
73 * Get the value of a boolean belonging to parent object and named as the name variable.
74 * Returns false if not found. (Not the same as the boolean present but false.)
76 WS_DLL_PUBLIC
bool json_get_boolean(char *buf
, jsmntok_t
*parent
, const char *name
, bool *val
);
79 * Decode the contents of a JSON string value by overwriting the input data.
80 * Returns true on success and false if invalid characters were encountered.
82 WS_DLL_PUBLIC
bool json_decode_string_inplace(char *text
);
91 * Editor modelines - https://www.wireshark.org/tools/modelines.html
96 * indent-tabs-mode: nil
99 * vi: set shiftwidth=4 tabstop=8 expandtab:
100 * :indentSize=4:tabSize=8:noTabs=true: