# encoding/json

encoding/json is Go's standard-library package for encoding and decoding JSON, with Marshal and Unmarshal functions mapping between JSON and Go values.

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

## A new Go API for JSON

DevFeed: [A new Go API for JSON](<https://devfeed.tech/articles/a-new-go-api-for-json-119073.md>)

Original publisher: [Read original article](<https://go.dev/blog/jsonv2>)

Author: Michael Pratt, Joe Tsai, Daniel Martí, Johan Brandhorst-Satzkorn, Roger Peppe, Chris Hines, and Damien Neil

Published: 2026-11-04T00:00:00Z

Content type: article

Language: en

Sources: [Go](<https://devfeed.tech/sources/the-go-blog.md>)

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

Tags: [api](<https://devfeed.tech/tags/api.md>), [encoding](<https://devfeed.tech/tags/encoding.md>), [encoding-json](<https://devfeed.tech/tags/encoding-json.md>), [go](<https://devfeed.tech/tags/go.md>), [json](<https://devfeed.tech/tags/json.md>), [json-v2](<https://devfeed.tech/tags/json-v2.md>), [jsontext](<https://devfeed.tech/tags/jsontext.md>), [packages](<https://devfeed.tech/tags/packages.md>)

### AI overview

Go 1.27 makes `encoding/json/v2` and `encoding/json/jsontext` stable and generally available. `jsontext` handles JSON syntax with streaming value and token encoders and decoders; `v2` builds on it for Go value marshaling, adds options across its APIs, and supports streaming custom methods. Compared with v1, v2 rejects invalid UTF-8 and duplicate object names, matches struct fields case-sensitively, and encodes nil slices and maps as empty arrays and objects. Marshal performance is roughly at parity with v1, while unmarshal can be significantly faster, with reported benchmark gains up to 10x; custom types can benefit further by implementing the streaming interfaces. Existing v1 applications remain supported, and its behavior can be retained or adjusted through compatibility options for gradual migration.

### Source excerpt

Go 1.27 introduces new encoding/json/v2 and encoding/json/jsontext packages.

## 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: article

Language: en

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

Topics: [encoding/json](<https://devfeed.tech/topics/encoding-json.md>), [JSON](<https://devfeed.tech/topics/json.md>), [Data serialization](<https://devfeed.tech/topics/data-serialization.md>)

Tags: [api-layers](<https://devfeed.tech/tags/api-layers.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>), [missing-values](<https://devfeed.tech/tags/missing-values.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>), [values](<https://devfeed.tech/tags/values.md>), [zero](<https://devfeed.tech/tags/zero.md>)

### AI overview

Go's basic JSON unmarshalling leaves struct fields at their zero values when the corresponding JSON fields are absent, and it does not fail merely because fields are missing or unknown to the struct. This makes an omitted value indistinguishable from an explicitly supplied zero value. The excerpt also notes that `json.Decoder.DisallowUnknownFields` can reject JSON fields that have no matching struct field when exact input validation is needed. The text cuts off before showing how to distinguish an omitted field from an explicit zero.

### 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>), [encoding/json](<https://devfeed.tech/topics/encoding-json.md>), [Tutorial](<https://devfeed.tech/topics/tutorial.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>), [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>), [http](<https://devfeed.tech/tags/http.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>), [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>), [streaming](<https://devfeed.tech/tags/streaming.md>), [struct](<https://devfeed.tech/tags/struct.md>), [tag](<https://devfeed.tech/tags/tag.md>)

### AI overview

Go's `encoding/json` offers `Marshal`, which returns bytes, and `NewEncoder`, which writes to an `io.Writer`. For HTTP handlers, encoding before sending can expose encoding errors early enough to choose a failure status; streaming through an encoder may fail after the response has started, so such errors should be logged. The excerpt also contrasts quick map-based marshaling with structs, which define an outgoing schema, and notes that struct field tags customize 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?

## Scalable JSON Streaming with HTTP and Go - Ep.5

DevFeed: [Scalable JSON Streaming with HTTP and Go - Ep.5](<https://devfeed.tech/articles/scalable-json-streaming-with-http-and-go-ep-5-22271.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2024/11/scalable-json-streaming-with--http-and-go.html>)

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

Content type: tutorial

Language: en

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

Topics: [Streaming](<https://devfeed.tech/topics/streaming.md>), [encoding/json](<https://devfeed.tech/topics/encoding-json.md>), [json lines format](<https://devfeed.tech/topics/json-lines-format.md>), [JSON](<https://devfeed.tech/topics/json.md>), [dataset](<https://devfeed.tech/topics/dataset.md>), [Error Handling](<https://devfeed.tech/topics/error-handling.md>)

Tags: [advanced](<https://devfeed.tech/tags/advanced.md>), [chunked-transfer-json](<https://devfeed.tech/tags/chunked-transfer-json.md>), [decoding-json-streams](<https://devfeed.tech/tags/decoding-json-streams.md>), [efficient-json-handling](<https://devfeed.tech/tags/efficient-json-handling.md>), [encoding-json](<https://devfeed.tech/tags/encoding-json.md>), [encoding-json-in-go](<https://devfeed.tech/tags/encoding-json-in-go.md>), [go](<https://devfeed.tech/tags/go.md>), [go-json-encoding](<https://devfeed.tech/tags/go-json-encoding.md>), [go-json-memory-management](<https://devfeed.tech/tags/go-json-memory-management.md>), [handling-large-json-files](<https://devfeed.tech/tags/handling-large-json-files.md>), [http](<https://devfeed.tech/tags/http.md>), [http-chunked-encoding](<https://devfeed.tech/tags/http-chunked-encoding.md>), [json](<https://devfeed.tech/tags/json.md>), [json-chunked-transfer](<https://devfeed.tech/tags/json-chunked-transfer.md>), [json-error-logging](<https://devfeed.tech/tags/json-error-logging.md>), [json-lines-format](<https://devfeed.tech/tags/json-lines-format.md>), [json-lines-ndjson](<https://devfeed.tech/tags/json-lines-ndjson.md>), [json-object](<https://devfeed.tech/tags/json-object.md>), [json-streaming](<https://devfeed.tech/tags/json-streaming.md>), [json-streaming-in-go](<https://devfeed.tech/tags/json-streaming-in-go.md>), [large-datasets](<https://devfeed.tech/tags/large-datasets.md>), [logging](<https://devfeed.tech/tags/logging.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-efficient-data-transmission](<https://devfeed.tech/tags/memory-efficient-data-transmission.md>), [memory-efficient-json](<https://devfeed.tech/tags/memory-efficient-json.md>), [practical](<https://devfeed.tech/tags/practical.md>), [query](<https://devfeed.tech/tags/query.md>), [real-time-json-streaming](<https://devfeed.tech/tags/real-time-json-streaming.md>), [scalable-json-processing](<https://devfeed.tech/tags/scalable-json-processing.md>), [stream](<https://devfeed.tech/tags/stream.md>), [streaming](<https://devfeed.tech/tags/streaming.md>), [streaming-data](<https://devfeed.tech/tags/streaming-data.md>), [streaming-json-over-http](<https://devfeed.tech/tags/streaming-json-over-http.md>), [streaming-large-json-datasets](<https://devfeed.tech/tags/streaming-large-json-datasets.md>), [streams](<https://devfeed.tech/tags/streams.md>)

### AI overview

For large datasets, the text recommends streaming JSON Lines (NDJSON) instead of building one large JSON object in memory, sending records incrementally to reduce memory use. In Go, an encoder can write each object with a newline; decoding requires a loop that handles incoming data without memory reuse causing stale or incorrect values. Over HTTP/1.1, the response writer can be used to encode objects and flush after each one for incremental delivery. Once streaming begins, the HTTP status code cannot be changed, so the text emphasizes logging errors. It mentions Netcat demonstrations but provides no further details in the supplied excerpt.

### Source excerpt

Introduction: Welcome to the final episode of the JSON for Engineers series! In this concluding session, we tackle the challenges of working with large JSON datasets, exploring efficient strategies for streaming data while minimizing memory usage. These techniques enable developers to handle massive payloads without overburdening system resources, ensuring scalable and cost-effective applications. JSON Streaming: Using JSON Lines for memory-efficient data transmission. HTTP Chunked Encoding: Leveraging HTTP/1.1 chunked transfer encoding for streaming large datasets. Practical Error Handling: Logging and managing errors in streaming JSON responses. This episode starts by addressing the inefficiencies of constructing large JSON objects in memory when working with massive datasets, such as database query results. Instead of consuming significant memory to create one monolithic JSON object, the recommended approach involves using JSON Lines (NDJSON), a format where each line represents a separate JSON object. This method reduces memory requirements by transmitting data incrementally. Using Go's encoding/json package, developers can easily encode and stream multiple JSON objects, as it automatically appends newlines between objects. On the receiving end, decoding JSON streams requires careful looping to handle incoming data dynamically while avoiding memory reuse issues, which could lead to errors or stale data.

## 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: article

Language: en

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

Topics: [encoding/json](<https://devfeed.tech/topics/encoding-json.md>), [JSON](<https://devfeed.tech/topics/json.md>), [Data serialization](<https://devfeed.tech/topics/data-serialization.md>), [data type](<https://devfeed.tech/topics/data-type.md>)

Tags: [advanced-json-management-go](<https://devfeed.tech/tags/advanced-json-management-go.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>), [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>), [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>), [large](<https://devfeed.tech/tags/large.md>), [large-datasets](<https://devfeed.tech/tags/large-datasets.md>), [managing-large-json-datasets-in-go](<https://devfeed.tech/tags/managing-large-json-datasets-in-go.md>), [reducing-type-declarations-go](<https://devfeed.tech/tags/reducing-type-declarations-go.md>), [serialization](<https://devfeed.tech/tags/serialization.md>), [type](<https://devfeed.tech/tags/type.md>)

### AI overview

For large JSON responses in Go, decoding only the fields an application needs into anonymous structs can avoid a proliferation of named types; `encoding/json` ignores unreferenced fields. The excerpt also describes implementing Go's Marshaler and Unmarshaler interfaces to control JSON formatting, including unit conversions. It mentions mixed-type arrays as a topic, but provides no details on how to handle them.

### 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.

## Managing JSON Field Tags and Value Handling in Go - Ep.3

DevFeed: [Managing JSON Field Tags and Value Handling in Go - Ep.3](<https://devfeed.tech/articles/managing-json-field-tags-and-value-handling-in-go-ep-3-22265.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2024/10/json-the-fine-print-ep-3-managing-json-field-tags-and-value-handling-in-go.html>)

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

Content type: article

Language: en

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

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

Tags: [default-values-in-go-structs](<https://devfeed.tech/tags/default-values-in-go-structs.md>), [go](<https://devfeed.tech/tags/go.md>), [go-default-values](<https://devfeed.tech/tags/go-default-values.md>), [go-field-tagging-techniques](<https://devfeed.tech/tags/go-field-tagging-techniques.md>), [go-struct-mapping](<https://devfeed.tech/tags/go-struct-mapping.md>), [handling-flexible-json](<https://devfeed.tech/tags/handling-flexible-json.md>), [handling-missing-json-values](<https://devfeed.tech/tags/handling-missing-json-values.md>), [json](<https://devfeed.tech/tags/json.md>), [json-code-reliability](<https://devfeed.tech/tags/json-code-reliability.md>), [json-data-consistency](<https://devfeed.tech/tags/json-data-consistency.md>), [json-data-structures-go](<https://devfeed.tech/tags/json-data-structures-go.md>), [json-field-consistency-go](<https://devfeed.tech/tags/json-field-consistency-go.md>), [json-field-integration-in-go](<https://devfeed.tech/tags/json-field-integration-in-go.md>), [json-field-mapping](<https://devfeed.tech/tags/json-field-mapping.md>), [json-field-tagging-in-go](<https://devfeed.tech/tags/json-field-tagging-in-go.md>), [json-for-engineers](<https://devfeed.tech/tags/json-for-engineers.md>), [json-in-go](<https://devfeed.tech/tags/json-in-go.md>), [json-in-strongly-typed-languages](<https://devfeed.tech/tags/json-in-strongly-typed-languages.md>), [json-keys-to-go-fields](<https://devfeed.tech/tags/json-keys-to-go-fields.md>), [json-parsing](<https://devfeed.tech/tags/json-parsing.md>), [json-parsing-errors](<https://devfeed.tech/tags/json-parsing-errors.md>), [json-parsing-strategies-go](<https://devfeed.tech/tags/json-parsing-strategies-go.md>), [json-pointers-in-go](<https://devfeed.tech/tags/json-pointers-in-go.md>), [json-schema-handling](<https://devfeed.tech/tags/json-schema-handling.md>), [json-structs-in-go](<https://devfeed.tech/tags/json-structs-in-go.md>), [json-to-go-data-integration](<https://devfeed.tech/tags/json-to-go-data-integration.md>), [json-to-go-parsing](<https://devfeed.tech/tags/json-to-go-parsing.md>), [json-unmarshalling-in-go](<https://devfeed.tech/tags/json-unmarshalling-in-go.md>), [json-value-handling](<https://devfeed.tech/tags/json-value-handling.md>), [managing-missing-values-in-json](<https://devfeed.tech/tags/managing-missing-values-in-json.md>), [managing-zero-values-in-json](<https://devfeed.tech/tags/managing-zero-values-in-json.md>), [map-string-interface-json](<https://devfeed.tech/tags/map-string-interface-json.md>), [mapping-json-to-go-structs](<https://devfeed.tech/tags/mapping-json-to-go-structs.md>), [zero](<https://devfeed.tech/tags/zero.md>)

### AI overview

The episode explains how Go JSON struct tags map keys such as `user_ID` to Go fields such as `UserID`, avoiding manual mappings and supporting readable JSON output. It then addresses how unmarshalling makes absent fields hard to distinguish from fields set to Go's zero value. The excerpt describes pointers, which make absence detectable through `nil` but add nil checks and complexity, and maps, which allow key-existence checks through `map[string]interface{}`. It also introduces setting struct defaults before unmarshalling as a strategy, but the excerpt does not detail that method or complete the discussion of maps.

### Source excerpt

Introduction: Welcome to Episode 3 of JSON for Engineers! In this episode, Miki Tebeka explores the intricacies of JSON field mapping and value handling, especially when working in strongly typed languages like Go. This session covers the practical challenges of matching JSON fields to Go struct fields, distinguishing between missing and zero values, and using default values to ensure robust JSON parsing. These strategies are crucial for engineers managing flexible JSON data structures in a language with strict type requirements.

## Exploring JSON Encoding and Data Handling in Go - Ep.2

DevFeed: [Exploring JSON Encoding and Data Handling in Go - Ep.2](<https://devfeed.tech/articles/exploring-json-encoding-and-data-handling-in-go-ep-2-22264.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2024/10/json-the-fine-print-ep-2-exploring-json-encoding-and-data-handling-in-go.html>)

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

Content type: article

Language: en

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

Topics: [encoding/json](<https://devfeed.tech/topics/encoding-json.md>), [JSON](<https://devfeed.tech/topics/json.md>), [Go Language](<https://devfeed.tech/topics/go-language.md>), [Schema-less data format](<https://devfeed.tech/topics/schema-less-data-format.md>), [Serialization protocols](<https://devfeed.tech/topics/serialization-protocols.md>), [Web app](<https://devfeed.tech/topics/webapp.md>)

Tags: [challenges](<https://devfeed.tech/tags/challenges.md>), [data-transmission](<https://devfeed.tech/tags/data-transmission.md>), [debug](<https://devfeed.tech/tags/debug.md>), [decoding](<https://devfeed.tech/tags/decoding.md>), [efficient-data-encoding-in-go](<https://devfeed.tech/tags/efficient-data-encoding-in-go.md>), [encoding](<https://devfeed.tech/tags/encoding.md>), [encoding-json-in-go-with-type-assertions](<https://devfeed.tech/tags/encoding-json-in-go-with-type-assertions.md>), [fields](<https://devfeed.tech/tags/fields.md>), [flexibility](<https://devfeed.tech/tags/flexibility.md>), [format](<https://devfeed.tech/tags/format.md>), [go](<https://devfeed.tech/tags/go.md>), [go-encoding-json-package-tutorial](<https://devfeed.tech/tags/go-encoding-json-package-tutorial.md>), [go-interface-with-json](<https://devfeed.tech/tags/go-interface-with-json.md>), [go-json-handling](<https://devfeed.tech/tags/go-json-handling.md>), [go-programming-json-tips](<https://devfeed.tech/tags/go-programming-json-tips.md>), [go-strongly-typed-system-and-json](<https://devfeed.tech/tags/go-strongly-typed-system-and-json.md>), [go-types](<https://devfeed.tech/tags/go-types.md>), [handling-json-null-values-in-go](<https://devfeed.tech/tags/handling-json-null-values-in-go.md>), [json](<https://devfeed.tech/tags/json.md>), [json-decoding-in-go-examples](<https://devfeed.tech/tags/json-decoding-in-go-examples.md>), [json-encoding-in-go](<https://devfeed.tech/tags/json-encoding-in-go.md>), [json-marshalling-and-unmarshalling-in-go](<https://devfeed.tech/tags/json-marshalling-and-unmarshalling-in-go.md>), [json-schema-less-format-benefits-and-challenges](<https://devfeed.tech/tags/json-schema-less-format-benefits-and-challenges.md>), [json-vs-binary-formats-in-go](<https://devfeed.tech/tags/json-vs-binary-formats-in-go.md>), [mapping](<https://devfeed.tech/tags/mapping.md>), [mapping-json-to-go-types](<https://devfeed.tech/tags/mapping-json-to-go-types.md>), [package](<https://devfeed.tech/tags/package.md>), [pitfalls](<https://devfeed.tech/tags/pitfalls.md>), [practical](<https://devfeed.tech/tags/practical.md>), [protocol](<https://devfeed.tech/tags/protocol.md>), [schema](<https://devfeed.tech/tags/schema.md>), [web](<https://devfeed.tech/tags/web.md>), [web-applications](<https://devfeed.tech/tags/web-applications.md>), [working-with-json-in-go](<https://devfeed.tech/tags/working-with-json-in-go.md>)

### AI overview

JSON's schema-less flexibility can speed prototyping and accommodate varied data, but unexpected changes may introduce errors. In Go, mapping JSON values to strict types--including nullable fields and JSON numbers that do not align directly with Go's numeric types--can cause runtime problems; the excerpt mentions using type assertions and Go's JSON package to marshal structs and unmarshal data into Go types. It contrasts JSON's human readability, which helps debugging, with protocol buffers' smaller size and greater transmission efficiency, a tradeoff that matters when bandwidth is a concern.

### Source excerpt

Introduction: Welcome to Episode 2 of JSON for Engineers! In this episode, we explore the unique characteristics of JSON as a schema-less format, discussing both its benefits and challenges. You'll learn how JSON's flexibility, while enabling rapid development, can create issues when working with strongly-typed languages like Go. Additionally, we'll cover the differences between JSON and more compact binary formats, and how to handle JSON's broader use in web applications.

## Decode JSON Documents In Go

DevFeed: [Decode JSON Documents In Go](<https://devfeed.tech/articles/decode-json-documents-in-go-22092.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2014/01/decode-json-documents-in-go.html>)

Published: 2014-01-21T00:00:00Z

Content type: tutorial

Language: en

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

Topics: [encoding/json](<https://devfeed.tech/topics/encoding-json.md>), [JSON](<https://devfeed.tech/topics/json.md>), [webservice](<https://devfeed.tech/topics/webservice.md>)

Tags: [2](<https://devfeed.tech/tags/2.md>), [added](<https://devfeed.tech/tags/added.md>), [all](<https://devfeed.tech/tags/all.md>), [allowed](<https://devfeed.tech/tags/allowed.md>), [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [contain](<https://devfeed.tech/tags/contain.md>), [decode](<https://devfeed.tech/tags/decode.md>), [fields](<https://devfeed.tech/tags/fields.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [here](<https://devfeed.tech/tags/here.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [json](<https://devfeed.tech/tags/json.md>), [large](<https://devfeed.tech/tags/large.md>), [make](<https://devfeed.tech/tags/make.md>), [need](<https://devfeed.tech/tags/need.md>), [over](<https://devfeed.tech/tags/over.md>), [programming](<https://devfeed.tech/tags/programming.md>), [project](<https://devfeed.tech/tags/project.md>), [return](<https://devfeed.tech/tags/return.md>), [sample](<https://devfeed.tech/tags/sample.md>), [service](<https://devfeed.tech/tags/service.md>), [web](<https://devfeed.tech/tags/web.md>)

### AI overview

The excerpt presents a Go package fork built on Mitchell Hashimoto's mapstructure to decode selected fields from large JSON documents into simpler structs, even when those fields are nested at different levels. The motivation is to avoid defining every embedded struct required by json.Unmarshal while also avoiding direct work with a map. The added DecodePath function lets callers specify the fields and subdocuments they want; the excerpt begins an example but does not show how the function is used or describe its limitations or results.

### Source excerpt

Introduction We are working on a project where we have to make calls into a web service. Many of the web calls return very large documents that contain many sub-documents. The worst part is, we usually only need a handful of the fields for any given document and those fields tend to be scattered all over the place. Here is a sample of a smaller document: