Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/toon_format/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ def encode_object_as_list_item(
# Now encode the array content at depth + 1
encode_array_content(first_arr, options, writer, depth + 1)
else:
# If first value is an object, put "-" alone then encode normally
writer.push(depth, LIST_ITEM_PREFIX.rstrip())
encode_key_value_pair(first_key, first_value, options, writer, depth + 1)
# If first value is an object, put "- key:" then content at depth + 2
writer.push(depth, f"{LIST_ITEM_PREFIX}{first_key}:")
encode_value(first_value, options, writer, depth + 2)

# Rest of the keys go normally indented
for key, value in keys[1:]:
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/encode/arrays-nested.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@
},
"expected": "items[2]:\n - a: 1\n - [2]: 1,2",
"specSection": "7.3"
},
{
"name": "encodes array of nested objects",
"input": {
"items": [{ "a": { "b": 1 }}, { "c": 2 }]
},
"expected": "items[2]:\n - a:\n b: 1\n - c: 2",
"specSection": "10"
}
]
}
Loading