• Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Contributors
CoffeeRequired
Supported Minecraft Versions
  1. 1.8
  2. 1.9
  3. 1.10
  4. 1.11
  5. 1.12
  6. 1.13
  7. 1.14
  8. 1.15
  9. 1.16
  10. 1.17
  11. 1.18
  12. 1.19
banner-with-info.png


Requirements

  • Java 16+
  • Minecraft 1.16.5+
  • Skript 2.7.0

Where can I get help?
How can I start with SkJson?

All tutorials are based on the latest version [2.9[/backcolor][/font]

for the first time and recommend working with SkJson Documentation

️ Create json object/array from sources.


Code:
on script load:
  # From String
  # We can use escape sequences so two double quotes, or we can use single quote
  # Or we can define only KEYS without any quotes
  set {_json} to json from text "{""A"": false}"
  set {_json} to json from text "{'A': false}"
  set {_json} to json from text "{A: false}"

  # From file (json/yaml)
  # YAML: you can your old yaml file and SkJson will convert that to JSON file
  set {_json} to json from json file "plugins/SkJson/Files/test.json"
  set {_json} to json from yaml file "plugins/SkJson/Files/test.yaml"

  # From website
  # That will work only for GET! If you want to use other methods you should use requests
  set {_json} to json from website "https://dummyjson.com/products/1"

  # From any Skript/Bukkit object
  set {_json} to json from location(10, 20, 30, world("world"))
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 want for example Request's or work with files we have a small guide here.

️ Example for requests.

Suppose we have some API and we want to use Skript to work with that API and get JSON responses from that API (server), SkJson offers Request's according to its own.


Code:
on script load:
    async make POST request to "https://dummyjson.com/carts/add":
        header: "Content-Type: application/json"
        content: json from text "{userId: 1, products: [{id: 1, quantity: 1}, {id: 50, quantity: 2}]}"
        save incorrect response: true
        lenient: true
        save:
            content: {-content}
            headers: {-header}
            status code: {-code}
            url: {-url}
command response:
    trigger:
        send {-content} with pretty print
What does mean lenient ? lenient means attempting to repair corrupted JSON from a server response. (thanks to @mnight4)

️ Example for handling JSON file /wo cache.

SkJson can work with files whether it is writing, editing or appending. See also Write, New, Edit


Code:
# here we will create a new file
options:
    file_path: "plugins/SkJson/jsons/test.json"

on script load:
    new json file {@file_path} if json file {@file_path} does not exist

    # here we will work with the json file

    set {_json} to json from file {@file_path}

    # writing to file
    set {_data} to json from location(10, 20, 30, world("world"))
    write {_data} to json file {@file_path}

    # editing directly file
    edit value "world" of json file {@file_path} to "New World"

    # editing file with step over

    # getting the json file as Json object
    set {_json} to json from file {@file_path}
    set value of json object "world" in {_json} to "New World(By rewrote)"

    # write file back to JSON
    write {_json} to json file {@file_path}
️ Example for handling JSON file /w cache.

What is cache? Cache is known for storing JSON in memory instead of SkJson having to open and close the file it puts its reference in memory, and you are working with memory all the time and if you would like to save the file from memory to a real file. you can do it at any time with save <json-id>

Check out this documentation.: Write, New, Edit, Link File, Save File, Unlink File, Get Cached JSON


Code:
options:
    file_path: "plugins/SkJson/jsons/test.json"

on script load:
    # here we will create a new file
    new json file {@file_path} if json file {@file_path} does not exist
    # here we will linked our file to our memory.
    link json file {@file_path} as "your_specified_value" if json file {@file_path} exists

    # here we will set value to memory reference of your file.
    set value of json objct "location" in (json "your_specified_value") to location(10, 20, 30, world("world"))

    # here we will get location of memory
    set {_location} to value "location" of (json "your_specified_value")
    # that will return {"==":"org.bukkit.Location","yaw":0.0,"world":"world","x":10.0,"y":20.0,"z":30.0,"pitch":0.0}

    # here we will save memory reference back to file
    save json "your_specified_value"
️ Now we'll look at is how SkJson works with Skript/Bukkit objects

Code:
# let's say we have a command test and we work with Player Location.
command test:
  trigger:
    set {_json_location} to json from location of player
    teleport player to {_json_location}
    # that will teleport player to location converted from JSON object to location

    set {_item} to diamond sword named "Test"
    set lore of {_item} to "&6Gold" and "&7Silver"
    enchant {_item} with Sharpness 5
    set {_json_item} to json from {_item}

    give {_json_item} to player
So conclusion, if the Json object contains the correct object key Skript/SkJson will try to parse the JSON as a real object.
Author
CoffeeRequired
Downloads
142
Views
2,299
First release
Last update
Rating
5.00 star(s) 1 ratings

Latest updates

  1. Fix Reques HTTP sync handling, 1.20.6 Cache saving issue resolved.

    Full Changelog: https://github.com/cooffeeRequired/skJson/compare/3.0.7...3.0.91 [!IMPORTANT]...
  2. Fix nbt issues, add ~ as path identifier

    Full Changelog: https://github.com/cooffeeRequired/skJson/compare/3.0.6...3.0.7 [!IMPORTANT] ##...
  3. 3.0.6

    Full Changelog: https://github.com/cooffeeRequired/skJson/compare/3.0.5...3.0.6 [!IMPORTANT] Fix...

Latest reviews

Really good support! The author is very polite and professional. I love the idea and efficiency of this addon. Bugs get fixed very fast.