# JSON best practices

Published articles for JSON best practices.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## JSON - The Fine Print: Part 3 - Zero vs Missing Values

DevFeed: [JSON - The Fine Print: Part 3 - Zero vs Missing Values](<https://devfeed.tech/articles/json-the-fine-print-part-3-zero-vs-missing-values-22281.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2025/05/json-the-fine-print-part-3.html>)

Published: 2025-05-19T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [JSON](<https://devfeed.tech/topics/json.md>), [Go Language](<https://devfeed.tech/topics/go-language.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [api-layers](<https://devfeed.tech/tags/api-layers.md>), [code](<https://devfeed.tech/tags/code.md>), [common-serialization-errors](<https://devfeed.tech/tags/common-serialization-errors.md>), [data-serialization](<https://devfeed.tech/tags/data-serialization.md>), [data-structure-separation](<https://devfeed.tech/tags/data-structure-separation.md>), [data-transmission](<https://devfeed.tech/tags/data-transmission.md>), [data-validation](<https://devfeed.tech/tags/data-validation.md>), [encoding-json](<https://devfeed.tech/tags/encoding-json.md>), [go](<https://devfeed.tech/tags/go.md>), [go-json-types](<https://devfeed.tech/tags/go-json-types.md>), [go-language-serialization](<https://devfeed.tech/tags/go-language-serialization.md>), [go-language-validation](<https://devfeed.tech/tags/go-language-validation.md>), [go-type-mapping](<https://devfeed.tech/tags/go-type-mapping.md>), [json](<https://devfeed.tech/tags/json.md>), [json-best-practices](<https://devfeed.tech/tags/json-best-practices.md>), [json-go-mapping](<https://devfeed.tech/tags/json-go-mapping.md>), [json-marshaling](<https://devfeed.tech/tags/json-marshaling.md>), [json-unmarshaling](<https://devfeed.tech/tags/json-unmarshaling.md>), [json-validation](<https://devfeed.tech/tags/json-validation.md>), [passing-serialized-data](<https://devfeed.tech/tags/passing-serialized-data.md>), [rest-apis](<https://devfeed.tech/tags/rest-apis.md>), [schema-less-data-format](<https://devfeed.tech/tags/schema-less-data-format.md>), [serialization](<https://devfeed.tech/tags/serialization.md>), [serialization-mistakes](<https://devfeed.tech/tags/serialization-mistakes.md>), [serialization-protocols](<https://devfeed.tech/tags/serialization-protocols.md>), [unmarshalling](<https://devfeed.tech/tags/unmarshalling.md>)

### AI overview

This tutorial examines how to distinguish zero values from missing or NULL fields when consuming JSON in Go. It explains basic unmarshalling into structs, notes that absent fields do not cause errors, and introduces DisallowUnknownFields for validating exact JSON input.

### Source excerpt

Introduction In part 1 we took a higher level view on serialization in general and JSON in specific. In part 2 we looked at emitting JSON. In part 3, we'll look at an issue you might encounter when consuming JSON, Zero vs NULL field values. To clarify the definition of NULL, this means the absence of value. So here is the question: Given a field in a Go struct set to its zero value, how do you know that zero value was set by the user or it's zero because it was never provided?

## JSON - The Fine Print: Part 2 - Emitting JSON

DevFeed: [JSON - The Fine Print: Part 2 - Emitting JSON](<https://devfeed.tech/articles/json-the-fine-print-part-2-emitting-json-22267.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2024/10/json-the-fine-print-part-2.html>)

Published: 2025-02-04T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [JSON](<https://devfeed.tech/topics/json.md>), [API](<https://devfeed.tech/topics/api.md>), [Code](<https://devfeed.tech/topics/code.md>), [Structured-data](<https://devfeed.tech/topics/structured-data.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [api-layers](<https://devfeed.tech/tags/api-layers.md>), [code](<https://devfeed.tech/tags/code.md>), [common-serialization-errors](<https://devfeed.tech/tags/common-serialization-errors.md>), [data](<https://devfeed.tech/tags/data.md>), [data-serialization](<https://devfeed.tech/tags/data-serialization.md>), [data-structure-separation](<https://devfeed.tech/tags/data-structure-separation.md>), [data-transmission](<https://devfeed.tech/tags/data-transmission.md>), [data-validation](<https://devfeed.tech/tags/data-validation.md>), [encoding](<https://devfeed.tech/tags/encoding.md>), [encoding-json](<https://devfeed.tech/tags/encoding-json.md>), [function](<https://devfeed.tech/tags/function.md>), [go-json-types](<https://devfeed.tech/tags/go-json-types.md>), [go-language-serialization](<https://devfeed.tech/tags/go-language-serialization.md>), [go-language-validation](<https://devfeed.tech/tags/go-language-validation.md>), [go-type-mapping](<https://devfeed.tech/tags/go-type-mapping.md>), [http](<https://devfeed.tech/tags/http.md>), [io](<https://devfeed.tech/tags/io.md>), [io-writer](<https://devfeed.tech/tags/io-writer.md>), [json](<https://devfeed.tech/tags/json.md>), [json-best-practices](<https://devfeed.tech/tags/json-best-practices.md>), [json-go-mapping](<https://devfeed.tech/tags/json-go-mapping.md>), [json-marshaling](<https://devfeed.tech/tags/json-marshaling.md>), [json-unmarshaling](<https://devfeed.tech/tags/json-unmarshaling.md>), [json-validation](<https://devfeed.tech/tags/json-validation.md>), [map](<https://devfeed.tech/tags/map.md>), [passing-serialized-data](<https://devfeed.tech/tags/passing-serialized-data.md>), [properties](<https://devfeed.tech/tags/properties.md>), [rest-apis](<https://devfeed.tech/tags/rest-apis.md>), [schema](<https://devfeed.tech/tags/schema.md>), [schema-less-data-format](<https://devfeed.tech/tags/schema-less-data-format.md>), [serialization](<https://devfeed.tech/tags/serialization.md>), [serialization-mistakes](<https://devfeed.tech/tags/serialization-mistakes.md>), [serialization-protocols](<https://devfeed.tech/tags/serialization-protocols.md>), [standard](<https://devfeed.tech/tags/standard.md>), [structure](<https://devfeed.tech/tags/structure.md>), [writing](<https://devfeed.tech/tags/writing.md>)

### AI overview

This tutorial explains how to emit JSON in Go using the encoding/json package. It compares json.Marshal, which returns bytes, with json.Encoder, which writes to an io.Writer, and discusses error handling in HTTP handlers. It also demonstrates marshaling maps and structs and using field tags to control JSON property names.

### Source excerpt

Introduction In part 1 we took a high-level view on serialization and JSON. In this part, we'll roll our sleeves and start working with JSON, focused on emitting JSON. You might think this is a basic topic, but there is much more to it than just calling json.Marshal. json.Marshal vs json.Encoder The encoding/json package has two main APIs: Marshal and NewEncoder. The Marshal function returns a []byte while the NewEncoder function will write to an io.Writer. The question is: When should you use one API over the other?

## JSON Handling and Type Management with Large Datasets in Go - Ep.4

DevFeed: [JSON Handling and Type Management with Large Datasets in Go - Ep.4](<https://devfeed.tech/articles/json-handling-and-type-management-with-large-datasets-in-go-ep-4-22262.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2024/10/json-handling-and-type-management-with-large-datasets-in-go.html>)

Published: 2024-11-14T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [JSON](<https://devfeed.tech/topics/json.md>), [Code](<https://devfeed.tech/topics/code.md>), [data](<https://devfeed.tech/topics/data.md>)

Tags: [advanced-json-management-go](<https://devfeed.tech/tags/advanced-json-management-go.md>), [code](<https://devfeed.tech/tags/code.md>), [custom-go-struct-json-serialization](<https://devfeed.tech/tags/custom-go-struct-json-serialization.md>), [custom-json-serialization-go](<https://devfeed.tech/tags/custom-json-serialization-go.md>), [decoding](<https://devfeed.tech/tags/decoding.md>), [efficient-json-processing-in-go](<https://devfeed.tech/tags/efficient-json-processing-in-go.md>), [encoding-json](<https://devfeed.tech/tags/encoding-json.md>), [examples](<https://devfeed.tech/tags/examples.md>), [go](<https://devfeed.tech/tags/go.md>), [go-encoding-json-package](<https://devfeed.tech/tags/go-encoding-json-package.md>), [go-json-handling-tutorial](<https://devfeed.tech/tags/go-json-handling-tutorial.md>), [go-selective-decoding](<https://devfeed.tech/tags/go-selective-decoding.md>), [go-type-management-json](<https://devfeed.tech/tags/go-type-management-json.md>), [handling-mixed-type-arrays-json-go](<https://devfeed.tech/tags/handling-mixed-type-arrays-json-go.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [json](<https://devfeed.tech/tags/json.md>), [json-anonymous-structures-go](<https://devfeed.tech/tags/json-anonymous-structures-go.md>), [json-best-practices](<https://devfeed.tech/tags/json-best-practices.md>), [json-data-optimization-techniques](<https://devfeed.tech/tags/json-data-optimization-techniques.md>), [json-for-engineers](<https://devfeed.tech/tags/json-for-engineers.md>), [json-handling-techniques-for-engineers](<https://devfeed.tech/tags/json-handling-techniques-for-engineers.md>), [json-marshaler-and-unmarshaler-interfaces-in-go](<https://devfeed.tech/tags/json-marshaler-and-unmarshaler-interfaces-in-go.md>), [json-nested-fields-go](<https://devfeed.tech/tags/json-nested-fields-go.md>), [json-strategies-large-datasets](<https://devfeed.tech/tags/json-strategies-large-datasets.md>), [json-type-pollution-avoidance](<https://devfeed.tech/tags/json-type-pollution-avoidance.md>), [managing-large-json-datasets-in-go](<https://devfeed.tech/tags/managing-large-json-datasets-in-go.md>), [pitfalls](<https://devfeed.tech/tags/pitfalls.md>), [reducing-type-declarations-go](<https://devfeed.tech/tags/reducing-type-declarations-go.md>), [serialization](<https://devfeed.tech/tags/serialization.md>)

### AI overview

Episode 4 of the JSON for Engineers series explains how to process large JSON datasets in Go. It covers selective decoding with anonymous structures, custom JSON serialization through Marshaler and Unmarshaler interfaces, and handling mixed-type arrays.

### Source excerpt

Introduction: Welcome to Episode 4 of the JSON for Engineers series! In this episode, we tackle the complexities of working with JSON data, especially when dealing with extensive datasets and optimizing type management. Here, Miki introduces key strategies for managing large JSON documents, avoiding unnecessary type definitions, and using Go's encoding/json package to handle custom serialization needs effectively. Type Pollution Avoidance: Minimizing type declarations by using selective decoding and anonymous structures. Custom JSON Serialization: Implementing Go's Marshaler and Unmarshaler interfaces for precise JSON formatting. Working with Mixed-Type Arrays: Handling JSON arrays containing diverse types in Go Miki begins by addressing the challenge of "type pollution" when working with large JSON responses. When dealing with massive JSON datasets, like data from social trading platforms, defining a separate type for every possible field can quickly lead to an unwieldy codebase. To streamline this, Miki demonstrates how to leverage anonymous structures and selective decoding in Go. By defining only the relevant fields within a function, we can avoid creating additional struct types, making the code more compact and efficient. This technique is especially useful when working with JSON data containing nested fields that may not all be necessary for your application. Through this approach, Go's encoding/json package will simply ignore any unreferenced fields, allowing you to handle only the data that matters to your project.

## JSON - The Fine Print: Part 1

DevFeed: [JSON - The Fine Print: Part 1](<https://devfeed.tech/articles/json-the-fine-print-part-1-22266.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2024/10/json-the-fine-print-part-1.html>)

Published: 2024-10-23T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [JSON](<https://devfeed.tech/topics/json.md>), [API](<https://devfeed.tech/topics/api.md>)

Tags: [api-layers](<https://devfeed.tech/tags/api-layers.md>), [apis](<https://devfeed.tech/tags/apis.md>), [common-serialization-errors](<https://devfeed.tech/tags/common-serialization-errors.md>), [data-serialization](<https://devfeed.tech/tags/data-serialization.md>), [data-structure-separation](<https://devfeed.tech/tags/data-structure-separation.md>), [data-transmission](<https://devfeed.tech/tags/data-transmission.md>), [data-validation](<https://devfeed.tech/tags/data-validation.md>), [database](<https://devfeed.tech/tags/database.md>), [elasticsearch](<https://devfeed.tech/tags/elasticsearch.md>), [encoding-json](<https://devfeed.tech/tags/encoding-json.md>), [go-json-types](<https://devfeed.tech/tags/go-json-types.md>), [go-language-serialization](<https://devfeed.tech/tags/go-language-serialization.md>), [go-language-validation](<https://devfeed.tech/tags/go-language-validation.md>), [go-type-mapping](<https://devfeed.tech/tags/go-type-mapping.md>), [json](<https://devfeed.tech/tags/json.md>), [json-best-practices](<https://devfeed.tech/tags/json-best-practices.md>), [json-go-mapping](<https://devfeed.tech/tags/json-go-mapping.md>), [json-marshaling](<https://devfeed.tech/tags/json-marshaling.md>), [json-unmarshaling](<https://devfeed.tech/tags/json-unmarshaling.md>), [json-validation](<https://devfeed.tech/tags/json-validation.md>), [passing-serialized-data](<https://devfeed.tech/tags/passing-serialized-data.md>), [rest-apis](<https://devfeed.tech/tags/rest-apis.md>), [schema-less-data-format](<https://devfeed.tech/tags/schema-less-data-format.md>), [sensitive-data](<https://devfeed.tech/tags/sensitive-data.md>), [serialization](<https://devfeed.tech/tags/serialization.md>), [serialization-mistakes](<https://devfeed.tech/tags/serialization-mistakes.md>), [serialization-protocols](<https://devfeed.tech/tags/serialization-protocols.md>)

### AI overview

This article explains JSON and serialization fundamentals, then examines common mistakes. It recommends serializing data at program boundaries and using separate data structures for API, business, and storage layers to avoid inefficiency, coupling, and accidental exposure of sensitive data.

### Source excerpt

Introduction Everybody knows JSON, it's a simple serialization format and the default format for REST APIs. Like many other topics, there are fine points you should know in order to work with JSON more effectively and avoid common mistakes. In this article we'll explore some big picture aspects and some low level details of using JSON. Serialization Before diving into JSON, I'd like to take a look at serialization in general and discuss common mistakes I've seen my customers make.

## Data Integrity with JSON Serialization - Ep.1

DevFeed: [Data Integrity with JSON Serialization - Ep.1](<https://devfeed.tech/articles/data-integrity-with-json-serialization-ep-1-22263.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2024/10/json-the-fine-print-ep-1-data-integrity-with-json-serialization.html>)

Published: 2024-10-03T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [JSON](<https://devfeed.tech/topics/json.md>), [Software Engineering](<https://devfeed.tech/topics/software-engineering.md>), [software-architecture](<https://devfeed.tech/topics/software-architecture.md>)

Tags: [common-serialization-mistakes](<https://devfeed.tech/tags/common-serialization-mistakes.md>), [custom-json-validation](<https://devfeed.tech/tags/custom-json-validation.md>), [data-integrity-in-software-engineering](<https://devfeed.tech/tags/data-integrity-in-software-engineering.md>), [data-serialization-in-api-design](<https://devfeed.tech/tags/data-serialization-in-api-design.md>), [data-validation](<https://devfeed.tech/tags/data-validation.md>), [efficient-data-serialization](<https://devfeed.tech/tags/efficient-data-serialization.md>), [how-to-validate-json-data](<https://devfeed.tech/tags/how-to-validate-json-data.md>), [introduction-to-json-for-engineers](<https://devfeed.tech/tags/introduction-to-json-for-engineers.md>), [json](<https://devfeed.tech/tags/json.md>), [json-best-practices](<https://devfeed.tech/tags/json-best-practices.md>), [json-best-practices-for-api](<https://devfeed.tech/tags/json-best-practices-for-api.md>), [json-data-validation-techniques](<https://devfeed.tech/tags/json-data-validation-techniques.md>), [json-for-engineers](<https://devfeed.tech/tags/json-for-engineers.md>), [json-in-software-development](<https://devfeed.tech/tags/json-in-software-development.md>), [json-optimization-for-storage](<https://devfeed.tech/tags/json-optimization-for-storage.md>), [json-serialization-tutorial](<https://devfeed.tech/tags/json-serialization-tutorial.md>), [miki-tebeka-json-guide](<https://devfeed.tech/tags/miki-tebeka-json-guide.md>), [serialization](<https://devfeed.tech/tags/serialization.md>), [serialization-in-software-architecture](<https://devfeed.tech/tags/serialization-in-software-architecture.md>), [software-architecture](<https://devfeed.tech/tags/software-architecture.md>), [software-layer-separation-and-data-handling](<https://devfeed.tech/tags/software-layer-separation-and-data-handling.md>)

### AI overview

Episode 1 of JSON for Engineers explains serialization fundamentals and how JSON converts data structures to byte sequences. It recommends serializing at system boundaries such as APIs and storage, keeping native types internally, separating models across layers, and validating data beyond JSON syntax.

### Source excerpt

Introduction: Welcome to Episode 1 of JSON for Engineers! In this first episode, Miki Tebeka dives into the fundamentals of serialization, with a special focus on JSON, one of the most widely-used data formats in software engineering. Miki draws from his extensive development experience to explain how JSON fits into the bigger picture of data interchange and serialization, laying the groundwork for engineers to use it effectively in real-world applications.