Giter VIP home page Giter VIP logo

jjson's Introduction

JavaJson(Jjson)

It is a library for managing, generating and working with Json, which is built without using any additional libraries

Java version

This library was built for Java 17, the latest LTS. Click to download

Install

Download Maven

  • Step 1. Download The Jjson JAR file

CURL

curl -L -o 'bardiademon.Jjson-2.2.1.jar' 'https://github.com/bardiademon/Jjson/raw/main/releases/bardiademon.Jjson-2.2.1.jar'

Windows

Invoke-WebRequest -Uri 'https://github.com/bardiademon/Jjson/raw/main/releases/bardiademon.Jjson-2.2.1.jar' -OutFile 'bardiademon.Jjson-2.1.1.jar'
  • Step 2. Install the Jjson JAR file
mvn install:install-file -Dfile='bardiademon.Jjson-2.2.1.jar' -DgroupId='com.bardiademon' -DartifactId='Jjson' -Dversion='2.2.1' -Dpackaging=jar
  • Step 3. Add the dependency
<dependency>
    <groupId>com.bardiademon</groupId>
    <artifactId>Jjson</artifactId>
    <version>2.2.1</version>
</dependency>

Usage

Creating an object from the JjsonObject class and putting values into it

public class JjsonObjectTest {
    public static void main(String[] args) {

        final JjsonObject jjsonObject = new JjsonObject();
        jjsonObject.put("id", "bardiademon");
        jjsonObject.put("name", "Bardia Namjoo");
        jjsonObject.put("programmer", true);
        jjsonObject.put("age", 27);

    }
}

Format

public class JjsonObjectTest {
    public static void main(String[] args) {

        final JjsonObject jjsonObject = new JjsonObject();
        jjsonObject.put("id", "bardiademon");
        jjsonObject.put("name", "Bardia Namjoo");
        jjsonObject.put("programmer", true);
        jjsonObject.put("age", 27);

        final String encode = jjsonObject.encode();
        System.out.println(encode);

        final String encodeFormatter = jjsonObject.encodeFormatter();
        System.out.println(encodeFormatter);
    }
}

output

{
  "id": "bardiademon",
  "name": "Bardia Namjoo",
  "programmer": true,
  "age": 27
}
{
  "id": "bardiademon",
  "name": "Bardia Namjoo",
  "programmer": true,
  "age": 27
}

Creating an object of the JjsonObject class with a String of Json

public class JjsonObjectTest {
    public static void main(String[] args) {

        try {
            final JjsonObject ofString = JjsonObject.ofString("{\"id\":\"bardiademon\",\"name\":\"Bardia Namjoo\",\"programmer\":true,\"age\":27}");
        } catch (JjsonException e) {
            throw new RuntimeException(e);
        }

    }
}
public class JjsonObjectTest {
    public static void main(String[] args) {

        try {
            final JjsonObject ofString = JjsonObject.ofString("{\n" +
                    "  \"id\": \"bardiademon\",\n" +
                    "  \"name\": \"Bardia Namjoo\",\n" +
                    "  \"programmer\": true,\n" +
                    "  \"age\": 27\n" +
                    "}");
        } catch (JjsonException e) {
            throw new RuntimeException(e);
        }

    }
}

Working with JjsonArray is the same way

public class JjsonArrayTest {
    public static void main(String[] args) throws JjsonException {

        Logger.disableLog(false);

        final var jjsonArray = JjsonArray.ofString("""
                [1,5,4.56,"Hi, I'm bardiademon\tJava Programmer",true,null,{},[],{"name":"bardiademon"},["Bardia Namjoo"],[{}],[[{}]],{"test":[{}]}]
                """);

        final var getter = (JjsonArrayGetter) jjsonArray;
        final var builder = (JjsonArrayBuilder) jjsonArray;
        final var encoder = (JjsonEncoder) jjsonArray;

        System.out.println(jjsonArray.encode());

        final var number = jjsonArray.getInteger(-1, 5);
        System.out.println("number.intValue() = " + number);

        builder.put(5);
        builder.put("New String");
        builder.put(JjsonObject.ofJjsonObject(getter.getJjsonObject(8)));
        builder.put(0, getter.getInteger(0) + getter.getInteger(0));
        builder.put(8, getter.getJjsonObject(8).getString("name"));

        System.out.println(encoder.encode());

        final String string = getter.getString(5, "DEFAULT VALUE");
        System.out.println("string = " + string);

        final Boolean aBoolean = getter.getBoolean(4);
        System.out.println("aBoolean = " + aBoolean);


    }
}

output

[
  1,
  5,
  4.56,
  "Hi, I'm bardiademon	Java Programmer",
  true,
  null,
  {},
  [],
  {
    "name": "bardiademon"
  },
  [
    "Bardia Namjoo"
  ],
  [
    {}
  ],
  [
    [
      {}
    ]
  ],
  {
    "test": [
      {}
    ]
  }
]
number.intValue() = 5
[
  2,
  5,
  4.56,
  "Hi, I'm bardiademon	Java Programmer",
  true,
  null,
  {},
  [],
  "bardiademon",
  [
    "Bardia Namjoo"
  ],
  [
    {}
  ],
  [
    [
      {}
    ]
  ],
  {
    "test": [
      {}
    ]
  },
  5,
  "New String",
  {
    "name": "bardiademon"
  }
]
string = DEFAULT VALUE
aBoolean = true

Json of File/Stream

public class JjsonTest {
    public static void main(String[] args) throws JjsonException, IOException {
        JjsonArray.ofFile("path");
        JjsonObject.ofFile("path");

        JjsonArray.ofStream(new FileInputStream("path"));
        JjsonObject.ofStream(new FileInputStream("path"));
    }
}

Json Write to file

public class JjsonTest {
    public static void main(String[] args) throws JjsonException, IOException {
        final JjsonObject jjsonObject = new JjsonObject();
        jjsonObject.put("id", "bardiademon");
        jjsonObject.put("name", "Bardia Namjoo");
        jjsonObject.put("programmer", true);
        jjsonObject.put("age", 27);

        jjsonObject.write("path");

        JjsonArray.create()
                .put(5)
                .put(3)
                .put(8)
                .write("path");
    }
}

Json Of Array/Collection/Map

import com.bardiademon.Jjson.JjsonArray.JjsonArray;
import com.bardiademon.Jjson.JjsonObject.JjsonObject;

import java.util.List;

public class JjsonTest {
    public static void main(String[] args) throws JjsonException, IOException {

        JjsonArray.ofCollection(Set.of(5L, 87L, 2L, 3L, 1L, 6L, 465L, 4L, 89L));
        JjsonArray.ofCollection(List.of(5L, 87L, 2L, 3L, 1L, 6L, 465L, 4L, 89L));
        JjsonArray.ofArray(new int[]{1, 23, 63, 54, 6, 755});
        JjsonArray.ofArray(new short[]{1, 23, 63, 54, 6, 755});
        JjsonArray.ofArray(new float[]{1.5F, 5, 4});

        final HashMap<Object, Object> hashMap = new HashMap<>();
        hashMap.put("id", "bardiademon");
        hashMap.put("firstname", "Bardia");
        hashMap.put("lastname", "Namjoo");

        JjsonObject.ofMap(hashMap);
    }
}

๐Ÿ’ป Technologies

Java

๐ŸŒŸ Spread the word!

If you want to say thank you:

  • Add a GitHub Star to the project!
  • Follow my GitHub bardiademon

โš ๏ธ License & ๐Ÿ“ Credits

by bardiademon https://bardiademon.com

jjson's People

Contributors

bardiademon avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.