Skip to content

Json values validation #268

Discussion options

You must be logged in to vote

If your input is a JSON array of employees, you can read the data row by row and reject bad records using the streaming (staj) API:

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

namespace ns {
    struct employee
    {
        std::string name;
        uint64_t id;
        int age;
    };
}

JSONCONS_ALL_MEMBER_TRAITS(ns::employee,name,id,age)

int main()
{
    std::string input = R"(
    [
      {
        "name" : "John Smith",
        "id" : 22,
        "age" : 34
      },
      {
        "name" : "",
        "id" : 23,
        "age" : 36
      },
      {
        "name" : "Jane Doe",
        "id" : 24,
        "age" : 345
      }
    ]
    )";

    jsoncons::json_cursor cursor(input…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dineshkumar02
Comment options

Answer selected by dineshkumar02
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