Skip to content

Conversation

@Vedant-03
Copy link

@Vedant-03 Vedant-03 commented Nov 14, 2025

Description

This PR fixes the encoding logic for array of nested objects. The current implementation encodes the JSON [{"a": {"b": "123"}}] as

[1]:
  -
    a:
      b: "123"

The change fixes this to be encoded as

[1]:
  - a:
      b: "123"

I have refined the logic for encoding object as list item to put the first key in a nested object on same line with "-" and continue encoding its corresponding value further according to SPEC.md. The decoding logic already looks good and needed change. This PR also adds a test case to validate the case.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test coverage improvement

Related Issues

Closes #33

Changes Made

  • Put the first key of nested object on the same line with "-", when encoding it as list item.
  • Added a test case to validate encoding array of nested object(s).

SPEC Compliance

  • This PR implements/fixes spec compliance
  • Spec section(s) affected:
    • 10
  • Spec version: 2.0

Testing

  • All existing tests pass
  • Added new tests for changes
  • Tested on Python 3.8
  • Tested on Python 3.9
  • Tested on Python 3.10
  • Tested on Python 3.11
  • Tested on Python 3.12
  • Tested on Python 3.13
  • Tested on Python 3.14

Test Output

==================================================== tests coverage ===================================================== 
____________________________________ coverage: platform win32, python 3.14.0-final-0 ____________________________________ 

Name                                Stmts   Miss   Cover   Missing
------------------------------------------------------------------
src\toon_format\__init__.py             6      0 100.00%
src\toon_format\__main__.py             4      4   0.00%   8-13
src\toon_format\_literal_utils.py      13      1  92.31%   58
src\toon_format\_parsing_utils.py      44      0 100.00%
src\toon_format\_scanner.py            80      0 100.00%
src\toon_format\_string_utils.py       60      0 100.00%
src\toon_format\_validation.py         29      0 100.00%
src\toon_format\cli.py                 77      1  98.70%   217
src\toon_format\constants.py           30      0 100.00%
src\toon_format\decoder.py            338     28  91.72%   98-99, 135, 156-157, 172, 183, 204, 364-365, 412-414, 529, 539,src\toon_format\encoder.py             21      1  95.24%   54
src\toon_format\logging_config.py      31      8  74.19%   83-92
src\toon_format\normalize.py           92      5  94.57%   25, 108-109, 116-117
src\toon_format\types.py               18      0 100.00%
src\toon_format\utils.py               37     25  32.43%   44-48, 61-62, 85-91, 120-131, 166-187
src\toon_format\writer.py              18      0 100.00%
------------------------------------------------------------------
================================================ short test summary info ================================================ 
============================================ 794 passed, 13 skipped in 5.66s ============================================

Code Quality

  • Ran ruff check src/toon_format tests - no issues
  • Ran ruff format src/toon_format tests - code formatted
  • Ran mypy src/toon_format - no critical errors
  • All tests pass: pytest tests/ -v

Checklist

  • My code follows the project's coding standards (PEP 8, line length 100)
  • I have added type hints to new code
  • I have added tests that prove my fix/feature works
  • New and existing tests pass locally
  • I have updated documentation (README.md, CLAUDE.md if needed)
  • My changes do not introduce new dependencies
  • I have maintained Python 3.8+ compatibility
  • I have reviewed the TOON specification for relevant sections

Performance Impact

  • No performance impact
  • Performance improvement (describe below)
  • Potential performance regression (describe and justify below)

Breaking Changes

  • No breaking changes
  • Breaking changes (describe migration path below)

Checklist for Reviewers

  • Code changes are clear and well-documented
  • Tests adequately cover the changes
  • Documentation is updated
  • No security concerns
  • Follows TOON specification
  • Backward compatible (or breaking changes are justified and documented)

@Vedant-03 Vedant-03 requested a review from a team as a code owner November 14, 2025 18:22
Copy link
Contributor

@Justar96 Justar96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @Vedant-03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decoder fails to parse nested objects within arrays (returns empty objects)

2 participants