MCPcopy Create free account
hub / github.com/ScrapeGraphAI/toonify / example_comparison

Function example_comparison

examples/pydantic_usage.py:238–267  ·  view source on GitHub ↗

Example: Size comparison between JSON and TOON.

()

Source from the content-addressed store, hash-verified

236
237
238def example_comparison():
239 """Example: Size comparison between JSON and TOON."""
240 print("=== Size Comparison: JSON vs TOON ===")
241
242 # Create a list of products
243 products = [
244 Product(sku=f'PROD-{i:03d}', name=f'Product {i}', price=float(10 + i), stock=100 - i)
245 for i in range(1, 11)
246 ]
247
248 # Convert to JSON
249 json_data = [p.model_dump() if hasattr(p, 'model_dump') else p.dict() for p in products]
250 json_str = json.dumps(json_data)
251
252 # Convert to TOON
253 toon_str = encode_pydantic(products)
254
255 print(f"Number of products: {len(products)}")
256 print(f"JSON size: {len(json_str)} bytes")
257 print(f"TOON size: {len(toon_str)} bytes")
258 print(f"Size reduction: {100 - (len(toon_str) / len(json_str) * 100):.1f}%")
259 print()
260
261 print("JSON format (first 200 chars):")
262 print(json_str[:200] + "...")
263 print()
264
265 print("TOON format:")
266 print(toon_str)
267 print()
268
269
270if __name__ == '__main__':

Callers 1

pydantic_usage.pyFile · 0.85

Calls 2

encode_pydanticFunction · 0.90
ProductClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…