A low-level lightweight JSON Database for java

Related tags

JSON java json maven
Overview

Simple JsonDB

JsonDB is a fast, light-weight JSON key-value storage engine for Java

What is key-value storage?

Installation

Pre-Requisites:

  • Java 1.8
  • Maven 1.4
    • Feel free to use newer versions of these but I
      can't promise that everything will work as intented


Start off by cloning the repository:

git clone https://github.com/AlexStan0/json-db

Then cd into the same directory as pom.xml and install/update maven dependencies:

mvn clean install -U

Follow up by creating the JAR file:

mvn package

You can use run the JAR using java -jar /path/to/json-db-1.0.jar or
you can import the jar into your maven project.

Usage

Import

if you just want the jar file

Add these lines to you pom.xml

<dependency>
    <groupId>com.jsondb</groupId>
    <artifactId>jsondb</artifactId>
    <version>1.0</version>
    <systemPath>/path/to/json-db-1.0.jar</systemPath>
</dependency>
import com.jsondb.JsonDB;

Instantiation

JsonDB db = new JsonDB(path)

The path for example is where your JSON file is located.
For example: C:/Users/<user>/path/to/javaProject/database.json

The constructor also checks if the file exists and if the file dosen't exist
it creates it in the the highest folder and writes {} to it

Set a key

db.set(key, value);

The provided key must always have a value or else the program will
throw an error and not write the data to the JSON file.

db.setObj(objKey, key, value)

This does the exact same thing as the previous set method but instead
it will create a new JSON Object, write the data, and associate the data with
the objKey as a nested JSON Object

Get a key

db.get(key, objKey)

This get method returns an Object, meaning that it can not return
an array. To do that you should use the db.arrGet(key, objKey) method

db.arrGet(key, objKey)

This method is the same as the get method but returns an
Object array instead of a simple Object type.

Check for a key

db.has(key, objKey)

If you want to check to see if your JSON file has a certain key you
can use the db.has() method to check for it.

Delete a key

db.delete(key, objKey)

If a certain key needs to be deleted you can delete it using the db.delete() method.
This method scans the JSON file to make sure the key exists and the deletes it. The objKey parameter
is used in case the key parameter is a nested JSON Object.

Delete everything

If you no longer need to use the database and don't want the IRS to find your data then this method is for you.
When you call db.delete() it creates a new JSON Object and overwrites the old one in the JSON file. Once this method
has been called all data previously written to the JSON file will be lost.

NOTE:

As you may have noticed both of these methods have a second parameter objKey.
This parameter is 100% optional and is ment to be use when the key parameter references a nested JSON Object

Example:
Say you had this JSON file

{
  "game-name": "my-game-name",
  "player 1": {
      "username": "KingSlayer123",
      "score": 274, 
      "health": 95,
      "inventory": ["sword", "potion", "bow", "arrows"]
  }
}

Say you wanted to check for the existance of game-name, you could call db.has("game-name")
But what if you wanted to check for the existance of score in the nested JSON Object player 1?
This is where the 'objKey' parameter comes in. If the 'key' paramter references a nested JSON Object it fetches or checks
for the existance of objKey in the nested JSON Object.

You might also like...

A fast JSON parser/generator for Java.

A fast JSON parser/generator for Java.

fastjson Fastjson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON str

Dec 31, 2022

Sawmill is a JSON transformation Java library

Sawmill is a JSON transformation Java library

Update: June 25, 2020 The 2.0 release of Sawmill introduces a breaking change to the GeoIpProcessor to comply with the updated license of the MaxMind

Jan 1, 2023

Genson a fast & modular Java Json library

Genson Genson is a complete json - java conversion library, providing full databinding, streaming and much more. Gensons main strengths? Easy to use

Jan 3, 2023

A reference implementation of a JSON package in Java.

JSON in Java [package org.json] Click here if you just want the latest release jar file. Overview JSON is a light-weight language-independent data int

Jan 6, 2023

Fast JSON parser for java projects

ig-json-parser Fast JSON parser for java projects. Getting started The easiest way to get started is to look at maven-example. For more comprehensive

Dec 26, 2022

A JSON Schema validation implementation in pure Java, which aims for correctness and performance, in that order

Read me first The current version of this project is licensed under both LGPLv3 (or later) and ASL 2.0. The old version (2.0.x) was licensed under LGP

Jan 4, 2023

Lean JSON Library for Java, with a compact, elegant API.

mJson is an extremely lightweight Java JSON library with a very concise API. The source code is a single Java file. The license is Apache 2.0. Because

Dec 25, 2022

A compiler built in Java that allows to translate xml format to json.

A compiler built in Java that allows to translate xml format to json. Getting Started Welcome to the VS Code Java world. Here is a guideline to help y

Jan 6, 2022

JSON-LD implementation for Java

JSONLD-Java is looking for a maintainer JSONLD-JAVA This is a Java implementation of the JSON-LD 1.0 specification and the JSON-LD-API 1.0 specificati

Dec 3, 2022
Comments
  • creating a nested JSON Object overwrites all other data in it

    creating a nested JSON Object overwrites all other data in it

    when using the objSet method it and try to add data to a nested JSONObject it overwrites all other data.

    For example, if you have this JSON file:

    "User 1": {
        "name": "John",
        "age": 27,
        "employer": "meta"
    }
    

    and you want to add another attribute to User 1 and you use the setObj method it will overwrite all other attributes and only saves the new one that you want.

    bug 
    opened by AlexStan0 0
Owner
Alexandru Stan
Look Guys, Bad Code!
Alexandru Stan
MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJO to JSON in a declarative way.

MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJ

Andrei Ciobanu 59 Sep 17, 2022
A simple java JSON deserializer that can convert a JSON into a java object in an easy way

JSavON A simple java JSON deserializer that can convert a JSON into a java object in an easy way. This library also provide a strong object convertion

null 0 Mar 18, 2022
JSON to JSON transformation library written in Java.

Jolt JSON to JSON transformation library written in Java where the "specification" for the transform is itself a JSON document. Useful For Transformin

Bazaarvoice 1.3k Dec 30, 2022
Generate Java types from JSON or JSON Schema and annotates those types for data-binding with Jackson, Gson, etc

jsonschema2pojo jsonschema2pojo generates Java types from JSON Schema (or example JSON) and can annotate those types for data-binding with Jackson 2.x

Joe Littlejohn 5.9k Jan 5, 2023
Essential-json - JSON without fuss

Essential JSON Essential JSON Rationale Description Usage Inclusion in your project Parsing JSON Rendering JSON Building JSON Converting to JSON Refer

Claude Brisson 1 Nov 9, 2021
A 250 lines single-source-file hackable JSON deserializer for the JVM. Reinventing the JSON wheel.

JSON Wheel Have you ever written scripts in Java 11+ and needed to operate on some JSON string? Have you ever needed to extract just that one deeply-n

Roman Böhm 14 Jan 4, 2023
Set level of characters in-game

SetLevel Basics This is a simple plugin to easily set character level in game. There will probably be issues if you don't use the commands as intended

Thoronium 15 Dec 16, 2022
A Java serialization/deserialization library to convert Java Objects into JSON and back

Gson Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to a

Google 21.7k Jan 8, 2023
A universal types-preserving Java serialization library that can convert arbitrary Java Objects into JSON and back

A universal types-preserving Java serialization library that can convert arbitrary Java Objects into JSON and back, with a transparent support of any kind of self-references and with a full Java 9 compatibility.

Andrey Mogilev 9 Dec 30, 2021
A modern JSON library for Kotlin and Java.

Moshi Moshi is a modern JSON library for Android and Java. It makes it easy to parse JSON into Java objects: String json = ...; Moshi moshi = new Mos

Square 8.7k Dec 31, 2022