A lightweight j(a)son library.

Related tags

Spring Boot Argo
Overview

Argo

Opus #18

A lightweight J(a)son library.

Description

This library converts json to Java's map/list object structure and vice-versa.
It is designed to be very small (one file plus a JsonException for nicer errors.)
It is designed to be as light as possible (interacts directly with streams with a ~16 byte buffer) and disposes of any closeable resources.

Json arrays are converted to ArrayLists for easier modification.

It is also possible to convert Java objects to and from json data directly. Note that the data is applied to the appropriate fields. Fields with illegal Java names (e.g. containing whitespace) will be ignored. Errors will be thrown if the field cannot be written to or the data is incompatible.

This is mainly designed for use with local classes for simpler data dispersion. Converting a json array will not convert its Object contents.

Maven Information

<repository>
    <id>kenzie</id>
    <name>Kenzie's Repository</name>
    <url>https://repo.kenzie.mx/releases</url>
</repository>
<dependency>
    <groupId>mx.kenzie</groupId>
    <artifactId>argo</artifactId>
    <version>1.1.2</version>
</dependency>

How to Use

Reading data...

From a json object:

// data = { "hello": true, "there": null }
// data is String / File / InputStream
try (final Json json = new Json(data)) {
    final Map<String, Object> map = json.toMap();
}

// Simple string -> map
final Map<String, Object> map = Json.fromJson(data);

From a json array:

// data = [ 1, 2, 3 ]
// data is String / File / InputStream
try (final Json json = new Json(data)) {
    final List<Object> list = json.toList();
}

Writing as json data:

// output is a File / Writer
// map is the data
new Json(output).write(map);

// fast object to json string
Json.toJson(map); // -> { ... }
Json.toJson(list); // -> [ ... ]

Converting json to an object:

class Result { int a, b; String hello; }
final String string = // { "a": 1, "b": 6, "hello": "there" }
final Result result = Json.fromJson(string, new Result());

Converting an object to json:

class Child { int bean = 3; }
class Result { String hello = "there"; Child child = new Child(); }
final Result result = new Result();
final String string = Json.toJson(result);
// string = { "hello": "there", "child": { "bean": 3 } }

Converting a type with an array:

// data = { "numbers": [0.5, 2.2, ...], "children": [ ... ] }
class Result { double[] numbers; Child[] children; }
final Result result = Json.fromJson(data, new Result());
assert result.numbers[1] == 2.2;
You might also like...

PipelinR is a lightweight command processing pipeline ❍ ⇢ ❍ ⇢ ❍ for your Java awesome app.

PipelinR PipelinR is a lightweight command processing pipeline ❍ ⇢ ❍ ⇢ ❍ for your awesome Java app. PipelinR has been battle-proven on production, as

Jan 8, 2023

RESTX, the lightweight Java REST framework

RESTX - the lightweight Java REST framework RESTX is a full lightweight disrupting stack, which includes Swagger-like ui & considers REST specs tests

Oct 22, 2022

Ethylene is a open-source, lightweight, general-purpose compatibility layer standing between the developer and the chaotic world of configuration file formats.

Ethylene Ethylene is a open-source, lightweight, general-purpose compatibility layer standing between the developer and the chaotic world of configura

Aug 9, 2022

A fast, lightweight and more productive microservices framework

A fast, lightweight and cloud-native microservices framework. Stack Overflow | Google Group | Gitter Chat | Subreddit | Youtube Channel | Documentatio

Jan 5, 2023

Lightweight mybatis page plugin

Lightweight mybatis page plugin

Jul 26, 2022

A simple and lightweight Minecraft GUI API for developers to use.

Current Version: 1.0.0 Requirements: - You must be using PaperMC or a fork of it (This will not work with just Spigot/Bukkit! - Curently this API only

May 14, 2022

A lightweight arthook Plugin.

A lightweight arthook Plugin.

ApoloPlugin ApoloPlugin 提供了一个Android轻量级的java hook 库,它支持 arm32 和 arm64两种架构。Apolo意为阿波罗,其为艺术之神,Art翻译过来也有艺术之意,故以此命名。 相关文档 Apolo插件实战-ROM环境注入app分析其行为 背景 Art

Jan 6, 2023

Lightweight and Necessary utilities for mini minecraft server

Lightweight and Necessary utilities for mini minecraft server

WithMyFriends Lightweight server tools for minimal servers. Contributing to us Version Strategy Why? Despite a huge amount of Server Essential Plugins

Mar 4, 2022

DatasetCreator is a lightweight RESTFul client implementation of the Salesforce CRM Analytics External Data API.

DatasetCreator is a lightweight RESTFul client implementation of the Salesforce CRM Analytics External Data API. It has been deliberately developed with no 3rd party jars with the goal of being a lean, reliable and scalable solution.

Dec 16, 2022
Comments
  • Make Argo a JPMS module

    Make Argo a JPMS module

    This PR adds a module-info.java file to Argo's source root, converting it to a JPMS module. This has several benefits:

    • More control over which Argo packages should be visible to API users
    • Explicit, compile-checked separation between internal functionality and the library API
    • Functionality in JPMS dependencies via jdk.unsupported requires declaration
    opened by bluelhf 0
Releases(1.1.4)
  • 1.1.4(Jul 16, 2022)

  • 1.1.1(Jul 10, 2022)

    This release allows arrays to be converted directly, rather than via objects. It also supports converting single-type json arrays.

    final int[] result = Json.fromJson("[1, 2, 3]", new int[0]);
    

    If arrays have a specified size they will trim any additional data.

    final int[] result = Json.fromJson("[1, 8, 3, 6, 7]", new int[2]);
    assert result.length == 2;
    

    This also works with objects of complex type, which will be converted.

    final MyClass[] result = Json.fromJson("[ {...}, {...} ]", new MyClass[0]);
    

    Full Changelog: https://github.com/Moderocky/Argo/compare/1.1.0...1.1.1

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Jul 10, 2022)

    This release contains an object <-> json conversion system. This is designed for accessing the json data more easily, rather than for serialisation.

    final String data = // { "a": 1, "b": 6, "hello": "there" }
    
    class Result { int a, b; String hello; }
    
    final Result result = Json.fromJson(data, new Result());
    
    assert result.a == 1;
    assert result.b == 6;
    assert result.hello.equals("there");
    
    result.a++;
    
    final String string = Json.toJson(result);
    // string = { "a": 2, "b": 6, "hello": "there" }
    

    Full Changelog: https://github.com/Moderocky/Argo/compare/1.0.0...1.1.0

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Jul 9, 2022)

Owner
Kenzie
I make things.
Kenzie
A lightweight and extensible library to resolve application properties from various external sources.

Externalized Properties A lightweight and extensible library to resolve application properties from various external sources. Twelve Factor Methodolog

Joel Jeremy Marquez 20 Nov 29, 2022
SDMLib is a lightweight modeling library

SDMLib is a lightweight modeling library. SDMLib intentionally comes without any tool or editor.

Fujaba Tool Suite 16 Dec 9, 2021
The lightweight library for compress image, video, and audio with an awesome experience

Would you like to support me? react-native-compressor Compress videos, images and audio before upload react-native-compressor package is a set of func

Shobbak 265 Jan 1, 2023
A lightweight and extensible library to resolve application properties from various external sources.

Externalized Properties A lightweight and extensible library to resolve application properties from various external sources. Twelve Factor Methodolog

Joel Jeremy Marquez 20 Nov 29, 2022
Lightweight React Native UI Components inspired on Vant

vant-react-native Install yarn add vant-react-native Or npm install vant-react-native Usage import React, { Component } from 'react'; import { View, T

洛竹 51 Sep 29, 2022
ESA ServiceKeeper is a lightweight service governance framework.

ServiceKeeper ServiceKeeper is a lightweight service governance framework that provides many awesome features such as rate limit, concurrent limit, ci

ESA Stack 22 Aug 11, 2022
Simple and lightweight application which is checking status of your web services and send a notification if it is down.

rose-uptimer Simple and lightweight application which is checking status of your web services and send a notification if it is down. Example configura

RoseSapphire 3 Sep 25, 2022
A libre lightweight streaming front-end for Android.

NewPipe A libre lightweight streaming frontend for Android. Screenshots • Description • Features • Installation and updates • Contribution • Donate •

Team NewPipe 22.4k Jan 3, 2023
Lightweight service-based PubSub, RPC and public APIs in Java

kite - service-based RPC, public APIs and PubSub in Java kite is a collection of reactive application messaging libraries that aim at providing high l

teris.io 3 Feb 17, 2022
Rivr is a lightweight open-source dialogue engine enabling Java developers to easily create enterprise-grade VoiceXML applications.

Overview Rivr is a lightweight open-source dialogue engine enabling Java developers to easily create enterprise-grade VoiceXML applications. Read our

Nu Echo Inc. 57 Jun 27, 2022