JSON to Nim Type Generator

Convert JSON data to Nim type definitions with proper type mapping, object types, and JSON serialization annotations.

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

  1. Paste your JSON object or array into the input area
  2. Configure options: root type name, JSON serialization, distinct types
  3. Click "Generate Nim Types" to create the code
  4. Copy the output and add it to your Nim project

Why Use This Tool?

Automatic type inference from JSON values
Nested object type generation with correct ordering (children first)
Option[T] for nullable fields following Nim conventions
seq[T] for arrays with proper element type inference
JSON serialization procs (toJson/fromJson) using the standard json module
Distinct types for stronger type safety on numeric fields

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.

Related Tools