You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Nested objects in array lose information on toonification #6
When toonifying nested JSON structures, certain properties (such as arrays of objects or strings) are lost in the output, even though token counts are reduced. This results in incomplete toonified data.
Steps to Reproduce
Use the following JSON input (inline below).
The data includes a nested array of objects under offset and an array of strings under hierarchy.
The resulting toonified JSON omits both the offset (array of objects) and hierarchy (array of strings) properties.
Token count is indeed reduced, but this reduction comes from the loss of meaningful structure and data.
See attached screenshot for reference:
Expected Behavior
Toonified output should preserve all properties (including nested arrays and objects), ensuring structural and semantic fidelity while still optimizing token usage.
Environment
package version: toonify-1.4.0
IDE: PyCharm (Notebook mode)
Experiment Context: Quick local test to measure token impact
Additional Context
I understand that this type of JSON doesn't fit neatly into traditional tabular data structures. However, supporting more complex, nested formats would significantly improve toonify's robustness, especially for real-world datasets used with LLMs where hierarchical or relational structures are common.
Suggested Improvement
Consider extending toonify's serialization logic to:
Preserve nested arrays and object properties.
Optionally flatten or represent them symbolically (e.g., offset[start:end] shorthand) without dropping information.
Provide a fallback or warning when certain structures can't be safely toonified.
Thank you for reporting this issue with such a detailed description and example. You're absolutely right - the nested arrays and objects were being lost during toonification.
What was the problem?
The encoder was using a compact tabular format for arrays of objects, but this format only preserved primitive fields (strings, numbers, booleans). When objects contained nested arrays like hierarchy or offset, these fields were silently dropped.
The Fix
I've modified the is_uniform_array_of_objects() function to detect when objects contain non-primitive fields (nested arrays or objects). When detected, the encoder now uses the list array format instead, which properly preserves all nested structures.
Your example data now correctly roundtrips with all fields preserved:
✅ hierarchy array of strings is preserved
✅ offset array of objects is preserved
✅ All primitive fields are preserved
✅ Full structural and semantic fidelity maintained
Activity
Fix: Preserve nested arrays and objects in tabular format (Issue #6)
VinciGit00 commentedon Nov 13, 2025
Hi @nomenclature95! 👋
Thank you for reporting this issue with such a detailed description and example. You're absolutely right - the nested arrays and objects were being lost during toonification.
What was the problem?
The encoder was using a compact tabular format for arrays of objects, but this format only preserved primitive fields (strings, numbers, booleans). When objects contained nested arrays like
hierarchyoroffset, these fields were silently dropped.The Fix
I've modified the
is_uniform_array_of_objects()function to detect when objects contain non-primitive fields (nested arrays or objects). When detected, the encoder now uses the list array format instead, which properly preserves all nested structures.Your example data now correctly roundtrips with all fields preserved:
hierarchyarray of strings is preservedoffsetarray of objects is preservedTesting
I've added comprehensive tests covering:
All 107 existing tests pass without regression.
Pull Request
The fix is ready for review in PR #7: #7
Thank you again for the excellent bug report! 🎉
Merge pull request #7 from ScrapeGraphAI/fix/nested-arrays-issue-6
chore(release): 1.5.0 [skip ci]
github-actions commentedon Nov 20, 2025
🎉 This issue has been resolved in version 1.5.0 🎉
The release is available on:
v1.5.0Your semantic-release bot 📦🚀