포매터 및 코드
JSON을 Elixir 구조체로
Elixir structs with @enforce_keys and typespecs.
편집자 노트
Understanding · Structs, maps, and the @enforce_keys trick.
이 심층 챕터는 현재 영어로만 제공됩니다. 위의 변환 도구는 귀하의 언어로 작동하지만, 긴 설명 글은 아직 번역되지 않았습니다.
자주 묻는 질문
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.
사람들이 다음도 검색합니다.
관련 도구
More in this room.
- JSON을 TypeScript 인터페이스로JSON 샘플에서 유형을 추론하고 TS 인터페이스를 생성합니다.
- JSON을 C# 클래스로JSON 샘플에서 POCO 클래스를 생성합니다.
- JSON을 Java POJO로JSON 샘플에서 Java POJO를 생성합니다.
- JSON을 Python Dataclass로JSON에서 타입 힌트가 있는 데이터 클래스(선택 사항으로 Pydantic 포함)를 생성합니다.
- JSON을 Go Struct로`json:` 태그가 있는 관용적인 Go 구조체입니다.
- JSON을 Kotlin 데이터 클래스로모든 JSON 샘플을 위한 간결한 데이터 클래스입니다.