Skip to content

code-landscape/jsonparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Parser

A lightweight JSON parser library written in C++17.

点击此处查看中文文档

Features

  • Parse JSON from string or file
  • Support for all JSON types: null, boolean, number, string, array, object
  • Simple and intuitive API
  • Header-only style usage

Project Structure

.
├── include/
│   ├── jsonparser.h      # Header file
│   └── jsonparser.cpp    # Implementation
└── test.cpp              # Test program

Usage

#include "jsonread.h"

int main() {
    jsonread::JsonParser parser;
    
    // Parse from file
    auto json = parser.parseFile("data.json");
    double value = json["key"].asNumber();
    
    // Parse from string
    auto json2 = parser.parse(R"({"name": "test", "value": 123})");
    std::string name = json2["name"].asString();
    
    // Access nested values
    auto nested = json2["data"]["x"].asNumber();
    
    // Access array elements
    auto arrElement = json2["arr"][0].asNumber();
    
    return 0;
}

API

JsonValue

  • isNull(), isBool(), isNumber(), isString(), isArray(), isObject() - Type checking
  • asBool(), asNumber(), asString(), asArray(), asObject() - Get value
  • asInt(), asBoolOpt() - Optional type conversion
  • operator[] - Access object keys or array indices

JsonParser

  • parse(const std::string& jsonStr) - Parse JSON string
  • parseFile(const char* filePath) - Parse JSON file

Requirements

  • C++17 compatible compiler
  • g++ or gcc

About

A lightweight JSON parser library written in C++17.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages