Encode an array with its key prefix for object context.
(key: str, arr: list, level: int, opts: EncoderOptions)
| 191 | |
| 192 | |
| 193 | def _encode_array_with_key(key: str, arr: list, level: int, opts: EncoderOptions) -> str: |
| 194 | """Encode an array with its key prefix for object context.""" |
| 195 | if not arr: |
| 196 | return '[]' |
| 197 | |
| 198 | indent = get_indent(level, opts.indent) |
| 199 | |
| 200 | # Check if it's a uniform array of objects (tabular format) |
| 201 | fields = is_uniform_array_of_objects(arr) |
| 202 | if fields: |
| 203 | return _encode_tabular_array(arr, fields, level, opts, key=key) |
| 204 | |
| 205 | # Check if all elements are primitives (inline format) |
| 206 | if all(is_primitive(item) for item in arr): |
| 207 | return _encode_primitive_array(arr, opts) |
| 208 | |
| 209 | # Mixed array (list format) |
| 210 | return _encode_list_array(arr, level, opts, key=key) |
| 211 | |
| 212 | |
| 213 |
no test coverage detected
searching dependent graphs…