GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - XSAM/BubbleJSON: A lite JSON parser/generator for C++

BranchesTags
Open more actions menu

Latest commit

 

History

36 Commits
36 Commits

Folders and files

NameName
Last commit message
Last commit date
.idea
.idea
 
 
BubbleJSON
BubbleJSON
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
CMakeLists.txt
CMakeLists.txt
 
 
README.md
README.md
 
 
test.cpp
test.cpp
 
 
test.json
test.json
 
 
test_file.cpp
test_file.cpp
 
 
test_file.h
test_file.h
 
 

Repository files navigation

Bubble JSON

travis build status

A lite JSON parser/generator for C++

Features

  • small but complete
  • support Unicode
  • provide friendly operator [] to access data
  • using C++ standard library. It is cross-platform

Installation

BubbleJSON is a header-only C++ library. copy the BubbleJSON folder into the project or system include path. Make sure check for C++11 support.

To run test follow these steps:

  • Go to repository folder
  • cmake .
  • make
  • run bubbleJson_test

Example

This simple example show a way to parse/modify/stringify json with BubbleJSON

#include <iostream>
#include "BubbleJSON/BubbleJson.h"

using namespace bubbleJson;

int main()
{
    // parse char* or string type json into tuple<Parse>
    const char* json = "{\"project\":\"BubbleJSON\",\"Compatibility\":\"C++11\"}";
    BubbleJson bubbleJson;

    auto result = bubbleJson.Parse(json);
    // parse ok, no error
    if (std::get<0>(result) != ParseResult_Ok)
        printf("parse error");

    // get value
    BubbleValue* value = std::get<1>(result);
    std::cout << (*value)["project"].GetString();

    // modify value
    (*value)["Compatibility"].SetArray(2);
    (*value)["Compatibility"][0].SetString("cpp11");
    (*value)["Compatibility"][1].SetString("all platform");

    // output stringify result, default Stringify_Type is beauty
    // output {"Compatibility":["cpp11","all platform"],"project":"BubbleJSON"}
    auto stringify = bubbleJson.Stringify(value, StringifyType_Minimum);
    std::cout << std::get<0>(stringify);

    // don't forget delete value, and free stringify result
    delete value;
    free (std::get<0>(stringify));

    return 0;
}

API

Parse or Stringify with BubbleJson

std::tuple<ParseResults, BubbleValue *> Parse(const char *json);
std::tuple<ParseResults, BubbleValue *> Parse(const std::string json);
// there are two stringify modes can choose, beauty and minimum
std::tuple<char*, size_t > Stringify(BubbleValue *bubbleValue, StringifyTypes stringifyType = StringifyType_Beauty);

Get data with BubbleValue

ValueTypes GetType();
void SetBoolean(bool boolean);
bool GetBoolean();
double GetNumber();
const char* GetString();
size_t GetStringLength();

BubbleValue* GetArrayElement(size_t index);
size_t GetArrayCount();

size_t GetObjectCount();
BubbleValue * GetObjectValueWithKey(const char *key);
BubbleValue * GetObjectValueWithKey(const std::string key);
std::map<std::string, BubbleValue> * GetObjects();

Set data with BubbleValue

void SetNull();
void SetNumber(double number);
void SetString(const char* string, size_t length);
void SetString(const std::string string);

void SetArray(size_t count);
void InsertArrayElementWithIndex(size_t index);
void DeleteArrayElementWithIndex(size_t index);

void SetObject();
void InsertObjectElementWithKey(const char *key, const size_t keyLength);
void InsertObjectElementWithKey(const std::string key);
void DeleteObjectElementWithKey(const char *key, const size_t keyLength);
void DeleteObjectElementWithKey(const std::string key);
// also you can invoke GetObjects with BubbleValue
// and set the return value whatever you want

operator [] with BubbleValue

BubbleValue& operator[](const size_t index);
BubbleValue& operator[](const size_t index) const;
BubbleValue& operator[](const int index);
BubbleValue& operator[](const int index) const;
BubbleValue& operator[](const char* key);
BubbleValue& operator[](const char* key) const;
BubbleValue& operator[](std::string key);
BubbleValue& operator[](std::string key) const;

About

A lite JSON parser/generator for C++

Topics

cppcpp-stlgeneratorjsonparser

Resources

Readme
Activity

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.