A simple scripting language in C++
Szontágh Ferenc
2025-04-19 571a9a1bafe0d8adddf3141f82213a47e4568baa
Document update
1 files modified
104 ■■■■■ changed files
docs/JsonModule.md 104 ●●●●● patch | view | raw | blame | history
docs/JsonModule.md
@@ -1,41 +1,63 @@
 # JsonModule
 Provides JSON serialization and deserialization functions.
 ## Functions
 ### json_encode
 - **Signature:** `json_encode(value) -> string`
 - **Description:** Serializes a VoidScript value to a JSON string.
 - **Parameters:**
   - `value`: A VoidScript value (int, double, bool, string, object, null).
 - **Returns:** JSON string representation.
 - **Errors:**
   - Incorrect number of arguments.
 ### json_decode
 - **Signature:** `json_decode(json) -> object|value`
 - **Description:** Parses a JSON string into a VoidScript value.
 - **Parameters:**
   - `json` (string): A valid JSON string.
 - **Returns:** VoidScript value (object, number, bool, null).
 - **Errors:**
   - Incorrect number of arguments.
   - `json` not a string.
   - Invalid JSON format.
 - **Note:** Only JSON objects (`{}`), primitives, and null are supported; arrays (`[]`) are not supported.
 ## Example
 ```vs
 var obj = {};
 obj["name"] = "Alice";
 obj["age"] = 30;
 var jsonStr = json_encode(obj);
 printnl(jsonStr);  // {"name":"Alice","age":30}
 var decoded = json_decode(jsonStr);
 printnl(decoded["name"]);  // Alice
 ```
# JsonModule
Provides JSON serialization and deserialization functions.
## Functions
### json_encode
* **Signature:** `json_encode(value) -> string`
* **Description:** Serializes a VoidScript value to a JSON string.
* **Parameters:**
  * `value`: A VoidScript value (int, double, bool, string, object, null).
* **Returns:** JSON string representation.
* **Errors:**
  * Incorrect number of arguments.
### json_decode
* **Signature:** `json_decode(json) -> object|value`
* **Description:** Parses a JSON string into a VoidScript value.
* **Parameters:**
  * `json` (string): A valid JSON string.
* **Returns:** VoidScript value (object, number, bool, null).
* **Errors:**
  * Incorrect number of arguments.
  * `json` not a string.
  * Invalid JSON format.
* **Note:** Only JSON objects (`{}`), primitives, and null are supported; arrays (`[]`) are not supported.
## Example
`# JSON Encode/Decode Feature Test`\
`# Define an object with nested data`\
`object $user = {`\
`    string name: "Alice",`\
`    int age: 30,`\
`    boolean active: true,`\
`    object prefs: {`\
`        string theme: "dark",`\
`        boolean notifications: false`\
`    }`\
`};`
`// Encode to JSON string`\
`string $json = json_encode($user);`\
`printnl("Encoded JSON: ", $json);`