Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON pointer (glz::get<T>) failing on json_t object #1441

Open
qudix opened this issue Nov 14, 2024 · 1 comment
Open

JSON pointer (glz::get<T>) failing on json_t object #1441

qudix opened this issue Nov 14, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@qudix
Copy link

qudix commented Nov 14, 2024

glaze v4.0.1

Using the following test:

{
    "test": true
}
#include <print>
#include <glaze/glaze.hpp>

int main()
{
    glz::json_t json;
    if (!glz::read_file_json(json, "test.json", std::string{}))
        std::println("found: {}", glz::get<bool>(json, "/test").has_value());
}

Expected: found: true
Actual: found: false

However using a custom struct works:

#include <print>
#include <glaze/glaze.hpp>

struct test_t
{
    bool test;
};

int main()
{
    test_t test{};
    if (!glz::read_file_json(test, "test.json", std::string{}))
        std::println("found: {}", glz::get<bool>(test, "/test").has_value());
}

To get around needing a struct, I found the following to also work:

#include <print>
#include <glaze/glaze.hpp>

int main()
{
    glz::json_t json;
    std::string json_buf;
    if (!glz::read_file_json(json, "test.json", json_buf))
        std::println("found: {}", glz::get_as_json<bool, "/test">(json_buf).has_value());
}

But that's unintuitive (and potentially an incorrect use). Is this an intended limitation?

@stephenberry
Copy link
Owner

The JSON pointer functions in Glaze were not developed for use with glz::json_t. However, I see how this could be very helpful and would make the library more cohesive. Thanks for bringing this up and I'll keep this issue alive until support has been added.

@stephenberry stephenberry added the enhancement New feature or request label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants