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
| Document | Description | Target Audience |
|---|---|---|
| index.md | Overview and key features | All developers |
| quickstart.md | 5-minute quick start guide | New developers |
| api-reference.md | Complete API reference | All developers |
| examples.md | Detailed code examples | All developers |
| best-practices.md | Best practices and tips | Advanced users |
| faq.md | Frequently asked questions | All 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 WithOutput:
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 WithCore Features
- Clear Type Mapping: Dictionary ↔ JSON object
{...}, Collection ↔ JSON array[...] - Separated Node Creation and Member Setting:
NewItem/NewItemscreate child nodes,Item/Itemsadd/modify members on nodes - Default Member:
Rootis the default member, allowing direct access viaJson("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
- Type Correspondence: Dictionary corresponds to JSON object
{...}, Collection corresponds to JSON array[...] - Root is Default Member: Directly access with
Json("key"), equivalent toJson.Root("key"), used for chained read/write - NewItem/NewItems Create Nodes:
NewItemcreates child object nodes,NewItemscreates child array nodes - Item/Items Modify Members:
Itemsets key-value pairs on object nodes,Itemsadds elements on array nodes - Array Index Starts from 1: VB's Collection object indexing starts from 1, unlike JavaScript
- Global Instance Shares Data:
VBMAN.Jsonis a global instance, data persists between uses; call.Clear()when necessary
Author Information
- Author: Deng Wei
- QQ: 215879458
- Based on: VBA-JSON v2.3.1 by Tim Hall (https://github.com/VBA-tools/VBA-JSON)
License
This documentation follows the project license.
Last updated: March 7, 2026