Skip to content

Commit 95d38c8

Browse files
Update README.md
1 parent 8dea53f commit 95d38c8

File tree

1 file changed

+156
-37
lines changed

1 file changed

+156
-37
lines changed

README.md

Lines changed: 156 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# SkJson 4.1 (WIP)
2-
31
![GitHub release](https://img.shields.io/github/release/SkJsonTeam/skJson?style=for-the-badge)
42
![GitHub issues](https://img.shields.io/github/issues-raw/SkJsonTeam/skJson?style=for-the-badge)
53
![GitHub closed issues](https://img.shields.io/github/issues-closed-raw/SkJsonTeam/skJson.svg?style=for-the-badge)
@@ -9,6 +7,8 @@
97
[![CodeFactor](https://www.codefactor.io/repository/github/cooffeerequired/skjson/badge)](https://www.codefactor.io/repository/github/cooffeerequired/skjson)
108
[![Java CI with Maven](https://github.com/SkJsonTeam/skJson/actions/workflows/maven.yml/badge.svg?branch=main)](https://github.com/SkJsonTeam/skJson/actions/workflows/maven.yml)
119

10+
11+
1212
<br />
1313

1414
[//]: # (<- Header ->)
@@ -17,53 +17,172 @@
1717
</p>
1818
<h1 align="center">SkJson <img align="center" style="border-radius: 20px;" alt="SkJson" width="5%" src="https://i.ibb.co/zV3Pxht/New-Project-4.png"></h1>
1919

20-
<h3 align="center">The modern way how to handle JSON in Skript</h3>
21-
<h6 align="center">The addon uses GSON (Google JSON) for work with JSON in Skript</h6>
20+
<h3 align="center">The modern way how to handle JSON in the Skript</h3>
21+
<h6 align="center">The addon uses GSON &#40;Google JSON&#41; for work with JSON in Skript</h6>
2222
<hr>
2323

24-
## 📑 Requirements
24+
### 📑 Requirements
2525

26-
* **Java 21+**
26+
* **Java 17+**
2727
* **Minecraft 1.16.5+**
28-
* **Skript 2.9.2+**
28+
* **Skript 2.8.0 +**
2929

30-
## 🔑 Recommended Tools
30+
### 🔑 Recommended
3131

32-
* **[Visual Studio Code](https://code.visualstudio.com/download)**
33-
* **[Skript Extension](https://marketplace.visualstudio.com/items?itemName=JohnHeikens.skript)**
32+
* **[**Visual Studio Code**](https://code-visualstudio-com.translate.goog/download?_x_tr_sl=en&_x_tr_tl=cs&_x_tr_hl=cs&_x_tr_pto=sc)**
33+
* **_[**Extension**](https://marketplace.visualstudio.com/items?itemName=JohnHeikens.skript)_**
3434

35-
## 🆘 Where Can I Get Help?
35+
### 🆘 Where can I get help?
3636

3737
* **[Discord](https://discord.gg/dsZq5Cs9fd)**
3838
* **[SkUnity](https://skunity.com/)**
39-
* **[Email](mailto:[email protected])** (Only for major issues and projects)
40-
41-
## 💡 What's New in SkJson?
42-
43-
The new version of SkJson is currently a **Work in Progress (WIP)**. Our goal is to make JSON handling in Skript easier and more efficient than ever before. This release will feature major improvements in terms of performance, usability, and compatibility, providing you with a seamless experience for all your scripting needs.
44-
45-
### Key Improvements:
46-
47-
- **Java 21+ Compatibility**: SkJson now requires Java 21 or higher, ensuring that the addon takes full advantage of the latest performance improvements and language features.
48-
- **Skript 2.9.2+ Compatibility**: Updated compatibility to require Skript 2.9.2+, providing better support and additional features that enhance your scripting workflow.
49-
- **Enhanced JSON Parsing**: The new version significantly optimizes JSON parsing using GSON, resulting in faster and more reliable JSON handling.
50-
- **Modular Architecture**: SkJson has been redesigned to offer a more modular architecture, making it easier to extend functionalities and customize the addon to fit your needs.
51-
- **Improved Error Handling**: Added detailed error messages and handling mechanisms to make debugging easier and to provide more insight into what might go wrong during JSON operations.
52-
- **Better Performance**: With the new Java version requirements, SkJson utilizes improved garbage collection and other JVM enhancements to boost performance, especially when dealing with large JSON structures.
53-
- **Streamlined API**: The API has been simplified to reduce complexity. Many methods have been refined to provide a more intuitive experience for developers.
54-
55-
### Upcoming Features:
56-
57-
- **File Handling Improvements**: Expect better integration for reading, writing, and updating JSON files with more control and options.
58-
- **Skript/Bukkit Object Serialization**: Enhanced capabilities for converting Bukkit and Skript objects directly into JSON and vice versa, making it even easier to work with in-game data.
59-
- **Advanced Request Handling**: Improved support for HTTP requests, including additional methods (POST, PUT, DELETE) with simplified syntax and more customization options.
60-
- **Async JSON Operations**: Support for asynchronous JSON processing to prevent lag during heavy JSON operations and to improve server responsiveness.
61-
62-
Stay tuned for the upcoming features and examples that will make working with JSON more powerful and intuitive!
39+
* **[Email](mailto:[email protected])** (Only the biggest projects)
40+
41+
### 💡 How can I start with SkJson?
42+
43+
#### All tutorials are based on the latest version **`2.9`**
44+
45+
for the first time and recommend working with [SkJson Documentation](https://skjson.xyz/)
46+
47+
#### 🗝️ Create json object/array from sources.
48+
49+
```shell
50+
on script load:
51+
# From String
52+
# We can use escape sequences so two double quotes, or we can use single quote
53+
# Or we can define only KEYS without any quotes
54+
set {_json} to json from text "{""A"": false}"
55+
set {_json} to json from text "{'A': false}"
56+
set {_json} to json from text "{A: false}"
57+
58+
# From file (json/yaml)
59+
# YAML: you can your old yaml file and SkJson will convert that to JSON file
60+
set {_json} to json from json file "plugins/SkJson/Files/test.json"
61+
set {_json} to json from yaml file "plugins/SkJson/Files/test.yaml"
62+
63+
# From website
64+
# That will work only for GET! If you want to use other methods you should use requests
65+
set {_json} to json from website "https://dummyjson.com/products/1"
66+
67+
# From any Skript/Bukkit object
68+
set {_json} to json from location(10, 20, 30, world("world"))
69+
```
70+
71+
This depends on what you want to do in SkJson, if you just want to work with JSON you can just use `Map/From` but if you
72+
want for example `Request's` or work with files we have a small guide here.
73+
74+
#### 🗝️ Example for requests.
75+
76+
Suppose we have some API and we want to use Skript to work with that API and get JSON responses from that API (server),
77+
SkJson offers [Request's](https://skjson.xyz/documentation/beta#section-Request) according to its own.
78+
79+
```sh
80+
on script load:
81+
async make POST request to "https://dummyjson.com/carts/add":
82+
header: "Content-Type: application/json"
83+
content: json from text "{userId: 1, products: [{id: 1, quantity: 1}, {id: 50, quantity: 2}]}"
84+
save incorrect response: true
85+
lenient: true
86+
save:
87+
content: {-content}
88+
headers: {-header}
89+
status code: {-code}
90+
url: {-url}
91+
command response:
92+
trigger:
93+
send {-content} with pretty print
94+
```
95+
96+
What does mean `lenient` ?
97+
**__`lenient`__** means attempting to repair corrupted JSON from a server response. (thanks to `@mnight4`)
98+
<br />
6399

64-
<hr>
100+
#### 🗝️ Example for handling JSON file /wo cache.
101+
102+
SkJson can work with files whether it is writing, editing or appending. See
103+
also [Write](https://skjson.xyz/documentation/beta#effect-Write), [New](https://skjson.xyz/documentation/beta#effect-New), [Edit](https://skjson.xyz/documentation/beta#effect-Edit)
104+
105+
```sh
106+
# here we will create a new file
107+
options:
108+
file_path: "plugins/SkJson/jsons/test.json"
109+
110+
on script load:
111+
new json file {@file_path} if json file {@file_path} does not exist
112+
113+
# here we will work with the json file
114+
115+
set {_json} to json from file {@file_path}
116+
117+
# writing to file
118+
set {_data} to json from location(10, 20, 30, world("world"))
119+
write {_data} to json file {@file_path}
120+
121+
# editing directly file
122+
edit value "world" of json file {@file_path} to "New World"
123+
124+
# editing file with step over
125+
126+
# getting the json file as Json object
127+
set {_json} to json from file {@file_path}
128+
set value of json object "world" in {_json} to "New World(By rewrote)"
129+
130+
# write file back to JSON
131+
write {_json} to json file {@file_path}
132+
```
133+
134+
#### 🗝️ Example for handling JSON file /w cache.
135+
136+
What is `cache`? Cache is known for storing JSON in memory instead of SkJson having to open and close the file it puts
137+
its reference in memory, and you are working with memory all the time and if you would like to save the file from memory
138+
to a real file. you can do it at any time with `save <json-id>`
139+
140+
Check out this
141+
documentation.: [Write](https://skjson.xyz/documentation/beta#effect-Write), [New](https://skjson.xyz/documentation/beta#effect-New), [Edit](https://skjson.xyz/documentation/beta#effect-Edit), [Link File](https://skjson.xyz/documentation/beta#effect-LinkFile), [Save File](https://skjson.xyz/documentation/beta#effect-SaveCache), [Unlink File](https://skjson.xyz/documentation/beta#effect-UnlinkFile), [Get Cached JSON](https://skjson.xyz/documentation/beta#expression-GetCachedJson)
142+
143+
```sh
144+
options:
145+
file_path: "plugins/SkJson/jsons/test.json"
146+
147+
on script load:
148+
# here we will create a new file
149+
new json file {@file_path} if json file {@file_path} does not exist
150+
# here we will linked our file to our memory.
151+
link json file {@file_path} as "your_specified_value" if json file {@file_path} exists
152+
153+
# here we will set value to memory reference of your file.
154+
set value of json objct "location" in (json "your_specified_value") to location(10, 20, 30, world("world"))
155+
156+
# here we will get location of memory
157+
set {_location} to value "location" of (json "your_specified_value")
158+
# that will return {"==":"org.bukkit.Location","yaw":0.0,"world":"world","x":10.0,"y":20.0,"z":30.0,"pitch":0.0}
159+
160+
# here we will save memory reference back to file
161+
save json "your_specified_value"
162+
```
163+
164+
#### 🗝️ Now we'll look at is how SkJson works with `Skript/Bukkit` objects
165+
166+
```sh
167+
# let's say we have a command test and we work with Player Location.
168+
command test:
169+
trigger:
170+
set {_json_location} to json from location of player
171+
teleport player to {_json_location}
172+
# that will teleport player to location converted from JSON object to location
173+
174+
set {_item} to diamond sword named "Test"
175+
set lore of {_item} to "&6Gold" and "&7Silver"
176+
enchant {_item} with Sharpness 5
177+
set {_json_item} to json from {_item}
178+
179+
give {_json_item} to player
180+
```
181+
182+
So conclusion, if the Json object contains the correct object key `Skript/SkJson` will try to parse the JSON as a real
183+
object.
184+
<hr />
65185
66186
[<img style="width: 20%" src="https://skripthub.net/static/addon/ViewTheDocsButton.png">](https://skripthub.net/docs/?addon=skJson)
67187
[<img style="width: 22%" src="https://skunity.com/branding/buttons/get_on_docs_4.png">](https://docs.skunity.com/syntax/search/addon:skjson)
68188
[<img style="width: 10%" src="https://static.spigotmc.org/img/spigot.png">](https://www.spigotmc.org/resources/skjson.106019/)
69-

0 commit comments

Comments
 (0)