Coder Social home page Coder Social logo

sos's Introduction

Simple C++ Object Serialization (SOS) Build Status

A minimal library to serialize C++ objects into JSON-like objects. Build a C++ object using the sos::* classes and serialize them into JSON or YAML. You can also provide your own custom serializers.

Usage

#include <iostream>
#include "sos.h"

int main(int argc, char** argv)
{
    // Build an object
    sos::Object root;

    // Build a string and add it to a key in the object
    root.set("username", sos::String("pksunkara"));

    // Build a number and add it to a key in the object
    root.set("age", sos::Number(25));

    // Build a boolean and add it to a key in the object
    root.set("literate", sos::Boolean(true));

    // Build a null and add it to a key in the object
    root.set("email", sos::Null());

    // Build an array
    sos::Array interests;

    // Push items into the array
    interests.push(sos::String("cricket"));
    interests.push(sos::String("programming"));

    // Change an already pushed item in the array
    interests.set(1, sos::String("computers"));

    // Set the array to a key in the object
    root.set("interests", interests);

    // Build the serializer
    sos::SerializeJSON serializer;

    // Output the serialization
    serializer.process(root, std::cout);
}

The above snippet will output the following JSON.

{
  "username": "pksunkara",
  "age": 25,
  "literate": true,
  "email": null,
  "interests": [
    "cricket",
    "computers"
  ]
}

Contribute

Fork & Pull Request

License

MIT License. See the LICENSE file.

sos's People

Contributors

pksunkara avatar kylef avatar klokane avatar w-vi avatar danielgtaylor avatar zdne avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.