Giter Site home page Giter Site logo

ultreon / json5-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marhali/json5-java

0.0 0.0 0.0 90 KB

This is a lightweight library to parse and serialize JSON5 data. Now with support to write comments!

License: Apache License 2.0

Java 100.00%

json5-api's Introduction

json5-java

Build JavaDoc Coverage Donate

This is a reference implementation of the JSON5 standard in Java 11+, capable of parsing and serialization of JSON5 data.

This library is an enhanced version of Synt4xErr0r4 / json5, which provides a better full-fledged API inspired by the GSON library.

Download

Download the latest release manually or add a Maven dependency. Don't worry the project is already in the Maven Central Repository. Just add the following configuration:

<dependencies>
    <dependency>
        <groupId>de.marhali</groupId>
        <artifactId>json5-java</artifactId>
        <version>2.0.0</version>
    </dependency>
</dependencies>

Usage

This library can be used by either configuring a Json5 instance or by using the underlying Json5Parser and Json5Writer.

The following section describes how to use this library with the Json5 core class.

Configure Json5 instance

See Parsing & Serialization Options to see a list of possible configuration options.

// Using builder pattern
Json5 json5 = Json5.builder(options ->
        options.allowInvalidSurrogate().quoteSingle().prettyPrinting().build());

// Using configuration object
Json5Options options = new Json5Options(true, true, true, 2);
Json5 json5 = new Json5(options);

Parsing

Json5 json5 = ...

// Parse from a String literal
Json5Element element = 
        json5.parse("{ 'key': 'value', 'array': ['first val','second val'] }");

// ...

// Parse from a Reader or InputStream
try(InputStream stream = ...) {
    Json5Element element = json5.parse(stream);
    // ...
} catch (IOException e) {
    // ...
}

Serialization

Json5Element element = ...

// Serialize to a String literal
String jsonString = json5.serialize(element);

// ...

// Serialize to a Writer or OutputStream        
try(OutputStream stream = ...) {
    json5.serialize(element, stream);
    // ...
} catch (IOException e) {
    // ...
}

Documentation

Detailed javadoc documentation can be found at javadoc.io.

Parsing & Serialization Options

This library supports a few customizations to adjust the behaviour of parsing and serialization. For a detailed explanation see the Json5Options class.

  • allowInvalidSurrogates
  • quoteSingle
  • trailingComma
  • indentFactor

License

This library is released under the Apache 2.0 license.

Partial parts of the project are based on GSON and Synt4xErr0r4 / json5. The affected classes contain the respective license notice.

json5-api's People

Contributors

dependabot[bot] avatar marhali avatar xypercode avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.