<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Go on</title><link>https://www.ardanlabs.com/categories/go/</link><description>Recent content in Go on</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 25 Nov 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://www.ardanlabs.com/categories/go/index.xml" rel="self" type="application/rss+xml"/><item><title>Scalable JSON Streaming with HTTP and Go - Ep.5</title><link>https://www.ardanlabs.com/blog/2024/11/scalable-json-streaming-with--http-and-go.html</link><pubDate>Mon, 25 Nov 2024 00:00:00 +0000</pubDate><guid>https://www.ardanlabs.com/blog/2024/11/scalable-json-streaming-with--http-and-go.html</guid><description>&lt;h3 id="introduction"&gt;Introduction:&lt;/h3&gt;&#10;&lt;p&gt;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.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;JSON Streaming:&lt;/strong&gt; Using JSON Lines for memory-efficient data transmission.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;HTTP Chunked Encoding:&lt;/strong&gt; Leveraging HTTP/1.1 chunked transfer encoding for streaming large datasets.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Practical Error Handling:&lt;/strong&gt; Logging and managing errors in streaming JSON responses.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;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 &lt;code&gt;encoding/json&lt;/code&gt; 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.&lt;/p&gt;</description></item><item><title>JSON Handling and Type Management with Large Datasets in Go - Ep.4</title><link>https://www.ardanlabs.com/blog/2024/10/json-handling-and-type-management-with-large-datasets-in-go.html</link><pubDate>Thu, 14 Nov 2024 00:00:00 +0000</pubDate><guid>https://www.ardanlabs.com/blog/2024/10/json-handling-and-type-management-with-large-datasets-in-go.html</guid><description>&lt;h3 id="introduction"&gt;Introduction:&lt;/h3&gt;&#10;&lt;p&gt;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.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Type Pollution Avoidance:&lt;/strong&gt; Minimizing type declarations by using selective decoding and anonymous structures.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Custom JSON Serialization:&lt;/strong&gt; Implementing Go’s Marshaler and Unmarshaler interfaces for precise JSON formatting.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Working with Mixed-Type Arrays:&lt;/strong&gt; Handling JSON arrays containing diverse types in Go&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;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.&lt;/p&gt;</description></item><item><title>Managing JSON Field Tags and Value Handling in Go - Ep.3</title><link>https://www.ardanlabs.com/blog/2024/10/json-the-fine-print-ep-3-managing-json-field-tags-and-value-handling-in-go.html</link><pubDate>Thu, 31 Oct 2024 00:00:00 +0000</pubDate><guid>https://www.ardanlabs.com/blog/2024/10/json-the-fine-print-ep-3-managing-json-field-tags-and-value-handling-in-go.html</guid><description>&lt;h3 id="introduction"&gt;Introduction:&lt;/h3&gt;&#10;&lt;p&gt;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.&lt;/p&gt;</description></item><item><title>Exploring JSON Encoding and Data Handling in Go - Ep.2</title><link>https://www.ardanlabs.com/blog/2024/10/json-the-fine-print-ep-2-exploring-json-encoding-and-data-handling-in-go.html</link><pubDate>Thu, 17 Oct 2024 00:00:00 +0000</pubDate><guid>https://www.ardanlabs.com/blog/2024/10/json-the-fine-print-ep-2-exploring-json-encoding-and-data-handling-in-go.html</guid><description>&lt;h3 id="introduction"&gt;Introduction:&lt;/h3&gt;&#10;&lt;p&gt;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&amp;rsquo;ll learn how JSON&amp;rsquo;s flexibility, while enabling rapid development, can create issues when working with strongly-typed languages like Go. Additionally, we&amp;rsquo;ll cover the differences between JSON and more compact binary formats, and how to handle JSON’s broader use in web applications.&lt;/p&gt;</description></item><item><title>Data Integrity with JSON Serialization - Ep.1</title><link>https://www.ardanlabs.com/blog/2024/10/json-the-fine-print-ep-1-data-integrity-with-json-serialization.html</link><pubDate>Thu, 03 Oct 2024 00:00:00 +0000</pubDate><guid>https://www.ardanlabs.com/blog/2024/10/json-the-fine-print-ep-1-data-integrity-with-json-serialization.html</guid><description>&lt;h3 id="introduction"&gt;Introduction:&lt;/h3&gt;&#10;&lt;p&gt;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.&lt;/p&gt;</description></item></channel></rss>