# mco_lJSON_obj_open
RT

### Prototype

        MCO_RET mco_lJSON_obj_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 JSON object as an element of the current JSON array. After this call, all subsequent JSON construction operations (e.g., `mco_lJSON_obj_add_str`, `mco_lJSON_obj_add_int`) will operate on this newly opened object 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 brace (`{`).

> 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 another object will result in an error.

>         ...
>         ret = mco_lJSON_obj_open_arr(&json_ctx, "hobbies");
>         if (ret == MCO_S_OK) {
>             ret = mco_lJSON_obj_open(&json_ctx);
>             if (ret != MCO_S_OK) {
>                 ...
>             }
>             // Add fields to the inner object, e.g.:
>             // mco_lJSON_add_str(&json_ctx, "sport", "hockey");
>             // mco_lJSON_add_int(&json_ctx, "level", 5);
>             ...
>             ret = mco_lJSON_obj_close(&json_ctx);
>             if (ret != MCO_S_OK) {
>                 printf("mco_lJSON_obj_close error %d\n", ret);
>             }
>         }
>         ...

### Return Codes

`MCO_S_OK`
JSON object successfully opened as a new array element.
`MCO_E_NW_SENDERR`
An error occurred while flushing the output buffer due to insufficient space for the opening brace (`{`).
`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