summaryrefslogtreecommitdiff
path: root/json.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-25 15:58:30 -0500
committerpommicket <pommicket@gmail.com>2022-12-25 15:58:30 -0500
commit9ee67ef5097451705b4ae9cb28895f726843cdf3 (patch)
tree6342192680691acb9151938c06f699e876c17819 /json.c
parentf67094bce357a76334a717ed669b377d3b93d18e (diff)
handle complete vs incomplete lists
Diffstat (limited to 'json.c')
-rw-r--r--json.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/json.c b/json.c
index 1174490..2dfb368 100644
--- a/json.c
+++ b/json.c
@@ -478,6 +478,20 @@ double json_array_get_number(const JSON *json, JSONArray array, size_t i) {
return json_force_number(json_array_get(json, array, i));
}
+bool json_force_bool(JSONValue x, bool default_value) {
+ if (x.type == JSON_TRUE) return true;
+ if (x.type == JSON_FALSE) return false;
+ return default_value;
+}
+
+bool json_object_get_bool(const JSON *json, JSONObject object, const char *name, bool default_value) {
+ return json_force_bool(json_object_get(json, object, name), default_value);
+}
+
+bool json_array_get_bool(const JSON *json, JSONArray array, size_t i, bool default_value) {
+ return json_force_bool(json_array_get(json, array, i), default_value);
+}
+
// returns (JSONString){0} (which is interpreted as an empty string) if `x` is not a string
JSONString json_force_string(JSONValue x) {
if (x.type == JSON_STRING) {