# mco_lJSON_arr_open
RT

### Prototype

        MCO_RET mco_lJSON_arr_open(lews_JSON_context_h json_ctx);

### Arguments

`json_ctx`
Pointer to an initialized `lews_JSON_context_t` structure.

### Description

> This function opens a new nested JSON array as an element of the current JSON array. After this call, all subsequent JSON construction operations (e.g., `mco_lJSON_arr_add_str`, `mco_lJSON_arr_add_int`) will operate on this newly opened inner array until it is closed with `mco_lJSON_obj_close()`.

> The function may trigger a buffer flush and send data over the network if there is insufficient space in the output buffer to write the opening bracket (`[`).

> This function can only be called when the current context is inside a JSON array. Attempting to call it at the root level or inside a JSON object will result in an error.

>         ...
>         ret = mco_lJSON_obj_open_arr(&json_ctx, "nested_arrays");
>         if (ret == MCO_S_OK) {
>             // First inner array
>             ret = mco_lJSON_arr_open(&json_ctx);
>             if (ret == MCO_S_OK) {
>                 mco_lJSON_arr_add_str(&json_ctx, "item1");
>                 mco_lJSON_arr_add_str(&json_ctx, "item2");
>                 mco_lJSON_obj_close(&json_ctx); // close inner array
>             }

>             // Second inner array
>             ret = mco_lJSON_arr_open(&json_ctx);
>             if (ret == MCO_S_OK) {
>                 mco_lJSON_arr_add_int(&json_ctx, 100);
>                 mco_lJSON_arr_add_int(&json_ctx, 200);
>                 mco_lJSON_obj_close(&json_ctx); // close inner array
>             }

>             mco_lJSON_obj_close(&json_ctx); // close "nested_arrays"
>         }
>         ...

### Return Codes

`MCO_S_OK`
Nested JSON array successfully opened as a new element of the current array.
`MCO_E_NW_SENDERR`
An error occurred while flushing the output buffer due to insufficient space for the opening bracket (`[`).
`MCO_E_LEWS_JSON_STACK_OVERFLOW`
The internal JSON nesting stack has reached its maximum depth.
`MCO_E_LEWS_PARENT_IS_NOT_ARRAY`
The current parent context is not a JSON array (e.g., you are at the root level or inside an object).
Other error codes
May indicate internal errors.

### Files

Header file:
mcoewslite.h
Source file:
mcoewslite.c
Library:
mcoewslite.a