diff options
author | pommicket <pommicket@gmail.com> | 2022-12-25 15:58:30 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-25 15:58:30 -0500 |
commit | 9ee67ef5097451705b4ae9cb28895f726843cdf3 (patch) | |
tree | 6342192680691acb9151938c06f699e876c17819 /json.c | |
parent | f67094bce357a76334a717ed669b377d3b93d18e (diff) |
handle complete vs incomplete lists
Diffstat (limited to 'json.c')
-rw-r--r-- | json.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -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) { |