or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdcore-api.mdcustomization.mdindex.mdnavigation.mdparsing.md
tile.json

tessl/maven-net-minidev--json-smart

JSON Small and Fast Parser - A lightweight, high-performance JSON processing library for Java

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/net.minidev/json-smart@2.6.x

To install, run

npx @tessl/cli install tessl/maven-net-minidev--json-smart@2.6.0

index.mddocs/

JSON-Smart

JSON-Smart is a lightweight, high-performance JSON processing library for Java that provides fast parsing, serialization, and dynamic navigation of JSON data. It offers both strict RFC4627 compliance and permissive parsing modes, along with extensive customization options.

Package Information

  • Package Name: net.minidev:json-smart
  • Package Type: maven
  • Language: Java
  • Version: 2.6.0-SNAPSHOT
  • Java Version: 8+
  • Installation:
    <dependency>
      <groupId>net.minidev</groupId>
      <artifactId>json-smart</artifactId>
      <version>2.6.0-SNAPSHOT</version>
    </dependency>

Core Imports

import net.minidev.json.JSONValue;
import net.minidev.json.JSONObject;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONNavi;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.JSONStyle;

Basic Usage

import net.minidev.json.JSONValue;
import net.minidev.json.JSONObject;
import net.minidev.json.JSONArray;

// Parse JSON string to Object
Object obj = JSONValue.parse("{\"name\": \"John\", \"age\": 30}");

// Parse to specific type
JSONObject person = JSONValue.parse("{\"name\": \"John\", \"age\": 30}", JSONObject.class);

// Create JSON objects programmatically
JSONObject user = new JSONObject()
    .appendField("name", "Alice")
    .appendField("age", 25)
    .appendField("active", true);

// Create JSON arrays
JSONArray numbers = new JSONArray()
    .appendElement(1)
    .appendElement(2)
    .appendElement(3);

// Serialize to JSON
String json = JSONValue.toJSONString(user);
System.out.println(json); // {"name":"Alice","age":25,"active":true}

// Validate JSON
boolean isValid = JSONValue.isValidJson("{\"test\": true}"); // true

Architecture

JSON-Smart uses a multi-layered architecture:

  • Entry Layer: JSONValue provides static utility methods for common operations
  • Object Model: JSONObject and JSONArray extend standard Java collections with JSON-specific functionality
  • Parser Layer: JSONParser handles configurable parsing with multiple modes (permissive, strict, streaming)
  • Navigation Layer: JSONNavi provides jQuery-like dynamic traversal and manipulation
  • Extension Layer: JsonReader/JsonWriter framework enables custom serialization/deserialization
  • Configuration Layer: JSONStyle and parser flags control output formatting and parsing behavior

Capabilities

Core JSON Operations

Essential JSON parsing, creation, and serialization functionality using JSONValue, JSONObject, and JSONArray.

// JSONValue - Main entry point
public static Object parse(String s);
public static <T> T parse(String s, Class<T> mapTo);
public static String toJSONString(Object value);
public static boolean isValidJson(String s);

// JSONObject - Object manipulation
public JSONObject appendField(String fieldName, Object fieldValue);
public String getAsString(String key);
public Number getAsNumber(String key);
public void merge(Object o2);

// JSONArray - Array manipulation  
public JSONArray appendElement(Object element);
public void merge(Object o2);

Core JSON Operations

Dynamic JSON Navigation

jQuery-like API for traversing and manipulating JSON structures without predefined types.

// JSONNavi factory methods
public static JSONNavi<JSONAwareEx> newInstance();
public static JSONNavi<JSONObject> newInstanceObject();
public static JSONNavi<JSONArray> newInstanceArray();

// Navigation methods
public JSONNavi<?> at(String key);
public JSONNavi<?> at(int index);
public JSONNavi<T> root();
public JSONNavi<?> up();

// Value access and mutation
public String asString();
public JSONNavi<T> set(String key, Object value);
public JSONNavi<T> add(Object... values);

Dynamic JSON Navigation

Advanced JSON Parsing

Configurable parsing with multiple modes, streaming support, and detailed error handling.

// JSONParser configuration
public static final int MODE_PERMISSIVE = 1;
public static final int MODE_RFC4627 = 2;
public static final int ACCEPT_SIMPLE_QUOTE = 1;
public static final int ACCEPT_NAN = 4;
public static final int ACCEPT_INCOMPLETE = 8192;

// Parsing methods
public Object parse(String in) throws ParseException;
public <T> T parse(String in, JsonReaderI<T> mapper) throws ParseException;

// MultipleJsonParser for streaming
public Object parseNext() throws ParseException;
public boolean hasNext();

Advanced JSON Parsing

Custom Serialization Framework

Extensible framework for implementing custom JSON serialization and deserialization logic.

// Registration methods
public static <T> void registerWriter(Class<?> cls, JsonWriterI<T> writer);
public static <T> void registerReader(Class<T> type, JsonReaderI<T> mapper);
public static <T> void remapField(Class<T> type, String jsonFieldName, String javaFieldName);

// Custom interfaces
public interface JsonWriterI<T> {
    <E extends T> void writeJSONString(E value, Appendable out, JSONStyle compression) throws IOException;
}

public abstract class JsonReaderI<T> {
    public abstract T convert(Object current);
    public void setValue(Object current, String key, Object value) throws ParseException, IOException;
}

Custom Serialization Framework

Output Formatting and Configuration

Control JSON output formatting, compression levels, and parser behavior through comprehensive configuration options.

// JSONStyle constants
public static final JSONStyle NO_COMPRESS;
public static final JSONStyle MAX_COMPRESS;
public static final JSONStyle LT_COMPRESS;

// Formatting flags
public static final int FLAG_PROTECT_KEYS = 1;
public static final int FLAG_PROTECT_VALUES = 4;
public static final int FLAG_IGNORE_NULL = 16;

// JSONStyle methods
public JSONStyle(int FLAG);
public boolean protectKeys();
public boolean ignoreNull();

Output Formatting and Configuration

Types

// Core exception type
class ParseException extends Exception {
    public int getErrorType();
    public int getPosition();
    public Object getUnexpectedObject();
}

// JSON interfaces
interface JSONAware {
    String toJSONString();
}

interface JSONAwareEx extends JSONAware {
    String toJSONString(JSONStyle compression);
}

interface JSONStreamAware {
    void writeJSONString(Appendable out) throws IOException;
}

interface JSONStreamAwareEx extends JSONStreamAware {
    void writeJSONString(Appendable out, JSONStyle compression) throws IOException;
}

// Annotation
@interface JsonIgnore {
    boolean value() default true;
}