Privvert - private browser-based file toolsPrivvert

JSON → TypeScript

Generera interfaces

Om det här verktyget

Paste any JSON sample and get strongly-typed TypeScript interfaces or types. Privvert detects optional fields by merging arrays of objects with different shapes, names nested types from their parent key, and quotes keys that aren't valid identifiers.

Useful for typing API responses, generating types from a config schema example, or kick-starting strongly-typed code from data you already have. Runs in your browser.

Funktioner

  • interface or type alias output
  • Merges array element shapes into one type with optionals
  • Names nested types from their parent key
  • Quoted keys for non-identifier names
  • Detects literal types where possible (booleans, common literals)
  • Browser-only - JSON never uploaded
  • Free and unlimited
  • Optional readonly modifier on every property

Så använder du det

  1. Paste a JSON example.
  2. Set the root type name.
  3. Pick interface or type output.
  4. Copy the generated TypeScript.
🔒 100 % privat

Allt sker i din webbläsare med JavaScript och WebAssembly. Dina filer laddas aldrig upp, lagras aldrig och ses aldrig av oss.

Vanliga frågor

Can it infer string literal unions?

Currently it produces 'string'. Literal-union inference (e.g. 'red' | 'green' | 'blue' from samples) is on the roadmap.

How does it detect optional fields?

When you provide an array of objects, the tool merges all element shapes. Fields that are missing from any element become optional (?: T).

Will it generate enums?

TypeScript types only, not enums. Use a literal union (one type alias with | between values) - that's the modern TypeScript-recommended approach over enums.

What if my JSON has very deeply nested objects?

The tool generates a separate named type for each nested object. Names come from the parent key (e.g. user.address → Address).

Does it handle arrays of mixed types correctly?

Yes - it generates union types when the array contains different shapes. For arrays of objects with optional fields, the resulting interface marks the missing fields as optional automatically.

Can I customise the root type name?

Yes. Type the name you want at the top of the input - the output will use it as the root interface. Nested types get sensible names derived from the parent property name.