Formateadores y código
JSON a Elixir Struct
Elixir structs with @enforce_keys and typespecs.
Nota del editor
Understanding · Structs, maps, and the @enforce_keys trick.
Este capítulo en profundidad está disponible solo en inglés por el momento. La herramienta de conversión de arriba funciona en tu idioma; el artículo explicativo extenso aún no se ha traducido.
Preguntas frecuentes
Quick answers.
›How are JSON types mapped to Elixir types?
Strings map to `String.t()`, numbers to `number()` or `float()`, booleans to `boolean()`, and nulls are handled as `nil`. Nested objects are converted into internal map definitions or separate struct placeholders.
›Does this tool handle nested JSON objects?
Yes. It will generate typespecs for nested structures, though you may need to manually extract nested maps into their own named modules for better Elixir project organisation.
›What is the purpose of @enforce_keys in the output?
The generator identifies keys present in your JSON and includes them in `@enforce_keys` to ensure the struct cannot be initialised without those specific attributes.
›Is my data sent to a backend for processing?
No. All transformation from JSON to Elixir code happens locally within your browser using JavaScript. No data is transmitted over the network.
La gente también busca
Herramientas relacionadas
More in this room.
- JSON a Interfaz TypeScriptInfiera tipos de una muestra JSON y emita interfaces TS.
- JSON a Clase C#Genere clases POCO a partir de una muestra JSON.
- JSON a POJO de JavaEmita un POJO de Java a partir de una muestra JSON.
- JSON a Dataclass de PythonDataclasses con sugerencia de tipo (con Pydantic opcional) desde JSON.
- JSON a Estructura GoEstructuras Go idiomáticas con etiquetas `json:`.
- JSON a Clase de Datos KotlinClases de datos concisas para cualquier muestra JSON.