Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bardiademon/jjson
JavaJson(Jjson)
https://github.com/bardiademon/jjson
bardiademon java java-json java17 javase json jsonarray jsonobject
Last synced: about 1 month ago
JSON representation
JavaJson(Jjson)
- Host: GitHub
- URL: https://github.com/bardiademon/jjson
- Owner: bardiademon
- Created: 2023-08-29T17:17:14.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-20T10:39:26.000Z (about 2 months ago)
- Last Synced: 2024-10-13T04:02:57.490Z (about 1 month ago)
- Topics: bardiademon, java, java-json, java17, javase, json, jsonarray, jsonobject
- Language: Java
- Homepage: https://bardiademon.com
- Size: 710 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JavaJson(Jjson)
It is a library for managing, generating and working with Json
Java version
-----This library was built for Java 17, the latest LTS.
[Click to download](https://dev.java)
-----Install
-----
[Download Maven](https://maven.apache.org/download.cgi)* Step 1. Download The Jjson JAR file
#### CURL
```bash
curl -L -o 'bardiademon.Jjson-2583.06.29.jar' 'https://github.com/bardiademon/Jjson/raw/main/releases/bardiademon.Jjson-2583.06.29.jar'
```#### Windows
```shell
Invoke-WebRequest -Uri 'https://github.com/bardiademon/Jjson/raw/main/releases/bardiademon.Jjson-2583.06.29.jar' -OutFile 'bardiademon.Jjson-2583.06.29.jar'
```* Step 2. Install the Jjson JAR file
```bash
mvn install:install-file -Dfile='bardiademon.Jjson-2583.06.29.jar' -DgroupId='com.bardiademon' -DartifactId='Jjson' -Dversion='2583.06.29' -Dpackaging=jar
```* Step 3. Add the dependency
```xml
com.bardiademon
Jjson
2583.06.29```
Usage
-----Creating an object from the JjsonObject class and putting values into it
```java
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
```java
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
```json
{
"id": "bardiademon",
"name": "Bardia Namjoo",
"programmer": true,
"age": 27
}
``````json
{
"id": "bardiademon",
"name": "Bardia Namjoo",
"programmer": true,
"age": 27
}
```Creating an object of the JjsonObject class with a String of Json
-----```java
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);
}}
}
``````java
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
-----```java
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
```json
[
1,
5,
4.56,
"Hi, I'm bardiademon Java Programmer",
true,
null,
{},
[],
{
"name": "bardiademon"
},
[
"Bardia Namjoo"
],
[
{}
],
[
[
{}
]
],
{
"test": [
{}
]
}
]
``````text
number.intValue() = 5
``````json
[
2,
5,
4.56,
"Hi, I'm bardiademon Java Programmer",
true,
null,
{},
[],
"bardiademon",
[
"Bardia Namjoo"
],
[
{}
],
[
[
{}
]
],
{
"test": [
{}
]
},
5,
"New String",
{
"name": "bardiademon"
}
]
``````text
string = DEFAULT VALUE
aBoolean = true
```Json of File/Stream
-----```java
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
-----```java
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
-----```java
import com.bardiademon.Jjson.array.JjsonArray;
import com.bardiademon.Jjson.object.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 hashMap = new HashMap<>();
hashMap.put("id", "bardiademon");
hashMap.put("firstname", "Bardia");
hashMap.put("lastname", "Namjoo");JjsonObject.ofMap(hashMap);
}
}
```
💻 Technologies
🌟 Spread the word!If you want to say thank you:
- Add a GitHub Star to the project!
- Follow my GitHub [bardiademon](https://github.com/bardiademon)
⚠️ License & 📝 Creditsby bardiademon [https://bardiademon.com](https://www.bardiademon.com)