Skip to content

quoted_num for numbers without quotes #1560

Answered by stephenberry
jstkdng asked this question in Q&A
Discussion options

You must be logged in to vote

Here is an example that makes use of glz::custom to create custom handling that first tries to parse as a JSON number and then will parse as a JSON string if that fails. (Compiler Explorer Link: https://gcc.godbolt.org/z/Yh57caKvs)

#include <iostream>

#include "glaze/glaze.hpp"

struct Command {
    std::string action;
    std::string preview_id;
    std::string image_scaler;

    int x = 0;
    int y = 0;
    int width = 0;
    int height = 0;
};

template <>
struct glz::meta<Command> {
    using T = Command;

    template <auto MemberPointer>
    static constexpr auto maybe_quoted_int_read = [](T& self, const glz::raw_json& json) {
        // first attempt to parse without quotes
        

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jstkdng
Comment options

@stephenberry
Comment options

Answer selected by jstkdng
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants