JSON to PureScript Type Generator

Convert JSON data into PureScript newtype or type alias definitions with proper type inference, Maybe types, and nested record support.

What is JSON to PureScript Type Generator?

This tool converts JSON data into PureScript type definitions with proper type inference. It automatically maps JSON types to PureScript types (String, Int, Number, Boolean, Maybe, Array) and handles nested objects as record types.

How to Use

  1. Select output format (newtype or type alias)
  2. Paste your JSON data into the input area
  3. Set the root type name
  4. Click "Generate" and copy the PureScript types

Why Use This Tool?

Automatically infer PureScript types from JSON values
Generate newtype or type alias definitions
Handle nested objects as separate type definitions
Map null values to Maybe types for type safety
Support for arrays with element type inference

Tips & Best Practices

  • Use realistic sample data for accurate type inference
  • Newtype wraps the record for type safety and instance derivation
  • Maybe types handle nullable JSON fields (Just value or Nothing)
  • Combine with argonaut-codecs or simple-json for JSON decoding

Frequently Asked Questions

How are JSON types mapped to PureScript?

JSON strings → String, integers → Int, floats → Number, booleans → Boolean, null → Maybe type, arrays → Array type, nested objects → separate record type definitions.

What is the difference between newtype and type alias?

A newtype creates a distinct type that wraps a record, providing type safety and allowing custom typeclass instances. A type alias is just a named shorthand for the record type — it does not create a new type.

How are null values handled?

JSON null values are mapped to PureScript Maybe types. For example, a nullable string field becomes Maybe String, which can be Just "value" or Nothing.

Can I use these types with JSON decoding?

Yes, the generated types work with PureScript JSON libraries. Use argonaut-codecs, simple-json, or foreign-generic to write decoders that match these type definitions.

Is my data sent to a server?

No, all processing happens entirely in your browser. Your JSON data never leaves your device.

Related Tools