What is JSON to Nim Type Generator?
This tool converts JSON data into Nim type definitions with proper type mapping, object types, and optional JSON serialization support. It generates ready-to-use Nim code with automatic type inference, Option[T] for nullable fields, seq[T] for arrays, and nested object type generation following Nim naming conventions.
How to Use
- Paste your JSON object or array into the input area
- Configure options: root type name, JSON serialization, distinct types
- Click "Generate Nim Types" to create the code
- Copy the output and add it to your Nim project
Why Use This Tool?
Tips & Best Practices
- Use realistic sample data for accurate type inference
- Enable JSON serialization to generate parseJson/toJson procs automatically
- Distinct types prevent accidental mixing of integer and float values
- Nim uses PascalCase for types and camelCase for fields by convention
Frequently Asked Questions
How are JSON types mapped to Nim types?
JSON strings map to string, integers map to int, floats map to float, booleans map to bool, null maps to Option[T] (optional), arrays map to seq[T], and nested objects map to separate Nim object types.
What is the difference between object and tuple in Nim?
Nim objects are reference types with named fields and support inheritance, while tuples are value types with ordered fields. This tool generates object types by default, which are the standard choice for representing JSON data structures in Nim.
How does JSON serialization work in Nim?
Nim's standard json module provides parseJson and toJson procs for serialization. When "Include JSON serialization" is enabled, the tool generates import json statements and helper procs that convert between your Nim types and JsonNode values using the standard library.
What are distinct types in Nim?
Distinct types in Nim create new types that are type-incompatible with their base type, preventing accidental mixing of values. When enabled, the tool wraps integer fields in DistinctInt and float fields in DistinctFloat for stronger type safety.
Is my JSON data sent to a server?
No, all processing happens entirely in your browser. Your JSON data never leaves your device.