
JSON Encoding
json.Marshal, json.Unmarshal, struct tags, custom marshaling, streaming, RawMessage
1Which function allows encoding a Go struct into JSON?
Which function allows encoding a Go struct into JSON?
Відповідь
json.Marshal encodes a Go struct into JSON bytes. This function reads struct tags to customize serialization (renaming, field omission). For streaming to io.Writer, using json.NewEncoder avoids creating an intermediate buffer in memory.
2Which function allows decoding JSON into a Go struct?
Which function allows decoding JSON into a Go struct?
Відповідь
json.Unmarshal decodes JSON bytes into a Go struct. A pointer to the target struct must be passed for data to be correctly written. For streaming from io.Reader, json.NewDecoder is more efficient as it avoids loading all JSON into memory.
3Which JSON struct tag allows renaming a field during serialization?
Which JSON struct tag allows renaming a field during serialization?
Відповідь
The json:"custom_name" tag allows renaming a field during JSON serialization. For example, a UserID field can become user_id in JSON. This is useful for respecting naming conventions (snake_case in JSON vs CamelCase in Go).
Which JSON struct tag completely excludes a field from serialization?
Which JSON struct tag allows omitting a field if its value is empty?
+17 питань зі співбесід
Інші теми співбесід Go
Go Basics
Go Data Structures
Go Interfaces
Error Handling
Goroutines Basics
Channels
Go Modules
HTTP Server
HTTP Client
database/sql
Context Package
Testing
Concurrency Patterns
Sync Primitives
Go Web Frameworks
REST API Design
gRPC
Reflection
Memory Management
Performance Optimization
Generics
Go Design Patterns
Microservices
Security & Authentication
Docker & Containerization
Kubernetes Basics
Advanced Go
CLI Development
Опануй Go для наступної співбесіди
Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.
Почни безкоштовно