$darkmode
main.cpp File Reference
#include <iostream>
#include <string>
#include <vector>
#include <optional>
#include <fmt/format.h>
#include <CLI/CLI.hpp>
#include <fable/confable.hpp>
#include <fable/schema.hpp>
#include <fable/utility.hpp>
Include dependency graph for main.cpp:

Classes

struct  Address
 
struct  Contact
 

Enumerations

enum class  PhoneType { Home , Mobile , Work , Other }
 

Functions

int main (int argc, char **argv)
 

Detailed Description

In this example application, we will define structs to serialize and deserialize JSON for contact persons.

We will be using the JSON from this Wikipedia article as our source format:

https://en.wikipedia.org/w/index.php?title=JSON&oldid=1027546414

The application should be able to serialize and deserialize to something like this:

{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 27,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }
  ],
  "children": [],
  "spouse": null
}

While we don't actually need to specify separate structs for the address, it improves readability significantly and makes working with optionals possible.