Skip to content

io microsphere json JSONUtils

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

JSONUtils

Type: Class | Module: microsphere-java-core | Package: io.microsphere.json | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/json/JSONUtils.java

Overview

Utility class for generating and manipulating JSON strings.

This abstract class provides a set of static methods to append different types of data into a JSON-formatted string using a StringBuilder. It supports primitive types, their wrapper classes, arrays (both primitive and object), collections like Map, Iterable, and custom objects through recursive value appending.

Example Usage

`StringBuilder builder = new StringBuilder();

// Appending simple key-value pairs:
JSONUtils.append(builder, "name", "John Doe");
// Result: {"name":"John Doe"`

// Appending nested objects:
JSONUtils.append(builder, "user", Map.of("id", 1, "active", true));
// Result: {"user":{"id":1,"active":true}}

// Appending arrays:
JSONUtils.append(builder, "numbers", new int[]{1, 2, 3});
// Result: {"numbers":[1,2,3]}

// Appending collections:
JSONUtils.append(builder, "tags", List.of("java", "json", "utils"));
// Result: {"tags":["java","json","utils"]}
}

Declaration

public abstract class JSONUtils implements Utils

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

StringBuilder builder = new StringBuilder();

// Appending simple key-value pairs:
JSONUtils.append(builder, "name", "John Doe");
// Result: {"name":"John Doe"}

// Appending nested objects:
JSONUtils.append(builder, "user", Map.of("id", 1, "active", true));
// Result: {"user":{"id":1,"active":true}}

// Appending arrays:
JSONUtils.append(builder, "numbers", new int[]{1, 2, 3});
// Result: {"numbers":[1,2,3]}

// Appending collections:
JSONUtils.append(builder, "tags", List.of("java", "json", "utils"));
// Result: {"tags":["java","json","utils"]}

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.json.JSONUtils;

API Reference

Public Methods

Method Description
append
append
append
append
append
append
append
append
append
append
append
append
append
append
append
append
append
append
append
append

See Also

  • StringBuilder

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally