Skip to content

cJson Developer Documentation

Introduction

cJson is the JSON processing class provided by the VBMAN framework, improved and encapsulated based on VBA-JSON v2.3.1. It provides a simple and easy-to-use API to parse and generate JSON data, supporting nested objects, arrays, file operations, and more.

Documentation Navigation

DocumentDescriptionTarget Audience
index.mdOverview and key featuresAll developers
quickstart.md5-minute quick start guideNew developers
api-reference.mdComplete API referenceAll developers
examples.mdDetailed code examplesAll developers
best-practices.mdBest practices and tipsAdvanced users
faq.mdFrequently asked questionsAll developers

Quick Start

Add Reference

Ensure your project has a reference to the VBMAN library added.

Simplest Example

vb
'Create a JSON object
With New VBMANLIB.cJson
    .Item("name") = "John"
    .Item("age") = 25
    MsgBox .Encode(, 2, True)
End With

Output:

json
{
  "name": "John",
  "age": 25
}

Parse a JSON String (Using Root)

vb
Dim JsonText As String
JsonText = "{""name"":""John"",""age"":25}"

With New VBMANLIB.cJson
    .Decode JsonText
    'Access using Root (default member) - recommended approach
    MsgBox .Root("name")  'Output: John
    'Or shorthand:
    MsgBox $("name")      'Output: John
End With

Core Features

  • Clear Type Mapping: Dictionary ↔ JSON object {...}, Collection ↔ JSON array [...]
  • Separated Node Creation and Member Setting: NewItem/NewItems create child nodes, Item/Items add/modify members on nodes
  • Default Member: Root is the default member, allowing direct access via Json("key") and supporting chained nesting
  • Nested Support: Unlimited levels of JSON object and array nesting
  • File Operations: Load and save JSON data from/to files
  • Encoding/Decoding: Bidirectional conversion between JSON strings and VB objects
  • Formatted Output: Custom indent formatting for JSON strings
  • Chinese Support: Display Chinese characters directly (no Unicode transcoding)
  • Array Indexing: Collection array indices start from 1 (following VB conventions)

Important Notes

  1. Type Correspondence: Dictionary corresponds to JSON object {...}, Collection corresponds to JSON array [...]
  2. Root is Default Member: Directly access with Json("key"), equivalent to Json.Root("key"), used for chained read/write
  3. NewItem/NewItems Create Nodes: NewItem creates child object nodes, NewItems creates child array nodes
  4. Item/Items Modify Members: Item sets key-value pairs on object nodes, Items adds elements on array nodes
  5. Array Index Starts from 1: VB's Collection object indexing starts from 1, unlike JavaScript
  6. Global Instance Shares Data: VBMAN.Json is a global instance, data persists between uses; call .Clear() when necessary

Author Information

License

This documentation follows the project license.


Last updated: March 7, 2026

VB6 and LOGO copyright of Microsoft Corporation