nlohmann::basic_json::is_string - renxiaobo27/json GitHub Wiki

bool is_string() const;

Description

Returns whether JSON container has type string.

Parameters

None.

Return value

true of value type is string, false otherwise.

Complexity

Constant.

Exceptions

None. The function's noexcept-specification is noexcept.

Example

#include <iostream>
#include <json.hpp>

int main()
{
    nlohmann::json j_null;
    nlohmann::json j_boolean = true;
    nlohmann::json j_number = 17;
    nlohmann::json j_object = {{"one", 1}, {"two", 2}};
    nlohmann::json j_array = {1, 2, 4, 8, 16};
    nlohmann::json j_string = "Hello, world";

    std::cout << std::boolalpha << j_null.is_string() << '\n';
    std::cout << std::boolalpha << j_boolean.is_string() << '\n';
    std::cout << std::boolalpha << j_number.is_string() << '\n';
    std::cout << std::boolalpha << j_object.is_string() << '\n';
    std::cout << std::boolalpha << j_array.is_string() << '\n';
    std::cout << std::boolalpha << j_string.is_string() << '\n';
}

Output

false
false
false
false
false
true

See also

⚠️ **GitHub.com Fallback** ⚠️