From 9895aa4b8d45ae8b662972bffb9bb128da74d0ed Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Fri, 8 Jan 2016 14:38:01 +0200 Subject: [PATCH] Allow 1 or 0 as boolean too --- pdns/json.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pdns/json.cc b/pdns/json.cc index 29e24f2ca..cab7fb4fa 100644 --- a/pdns/json.cc +++ b/pdns/json.cc @@ -93,9 +93,11 @@ bool boolFromJson(const Json container, const std::string& key) auto val = container[key]; if (val.is_bool()) { return val.bool_value(); - } else { - throw JsonException("Key '" + string(key) + "' not present or not a Bool"); + } else if (val.is_number()) { + if (val.int_value() == 1) return true; + else if (val.int_value() == 0) return false; } + throw JsonException("Key '" + string(key) + "' not present or not a Bool"); } bool boolFromJson(const Json container, const std::string& key, const bool default_value) @@ -103,7 +105,9 @@ bool boolFromJson(const Json container, const std::string& key, const bool defau auto val = container[key]; if (val.is_bool()) { return val.bool_value(); - } else { - return default_value; + } else if (val.is_number()) { + if (val.int_value() == 1) return true; + else if (val.int_value() == 0) return false; } + return default_value; } -- 2.40.0