Documentation

by skJson

Not optimalized for mobile devices yet.

Zkopírováno

Json file exists

You can check if the json file already exists or not.

Patterns


[skJson] json [file] %string% exists
[skJson] json [file] %string% does(n't| not) exist

Example


command FileExists:
	trigger
		set {_json} to json from string "{'A': [{'B': {}}, false, true, 10, 20, 22.22, 'A']}" if json file "plugins/test/main.json" already exists

2.8.0 - performance & clean

Json file is cached

Check if the file for given id is cached

Patterns


[skJson] json %string% is (load|linked)
[skJson] json %string% is(n't| not) (load|linked)

Example


on load:
	send true if json "test" is linked 

2.8.0 - performance & clean

Json file is listening

Check if the file for given id is listening via JsonWatcher

Patterns


json %string% is listen
json %string% is(n't| not) listen

Example


on load:
	if json "test" is listen:
		send true

2.8.0 - performance & clean

Json has value/keys

You can check if the inserted keys or values already in your specified json

Patterns


[skJson] %json% has [:directly] (:value|:key)[s] %objects%
[skJson] %json% does(n't| not) have [:directly] (:value|:key)[s] %objects%

Example


on script load:
	set {_json} to json from string "{'test5': [1], 'test6': ['key', 'key2', 'key3']}"
	if {_json} has keys "test5", "test6", "A":
		send true

2.8.0

Json is empty

You can check if the json empty

Patterns


[skJson] json(-| )element %json% is empty
[skJson] json(-| )element %json% is(n't| not) empty

Example


Command jsonIsEmpty
	trigger
		set {_json} to json from text "{}"
		send true if json element {_json} is empty

2.8.0 - performance & clean

Type of Json

You can get type of given Json.

Patterns


[skJson] type of %json% (is|=) (1:primitive|2:json object|3:json array)
[skJson] type of %json% (is(n't| not)|!=) (1:primitive|2:json object|3:json array)

Example


set {_j} to json from "{data: {}}"
if type of {_j} is json object

2.7

All json files in directory

You can get multiple file from directory and load that as json

Patterns


[skJson] All json [files] (from|in) (dir|directory|folder) %string%

Example


on script load:
	set {_jsons::*} to all json file from dir "./plugins/test"
	#Or you can loop trough that
	loop all json file from dir "./plugins/test":
		send loop-file
		send json from file loop-file

2.9.7

Changer - JsonArray set/add/remove/removeAll

The new documentation you will find here: click here

A very general effect that can change many json array. The json object can be only add/set/remove/removeAll

Patterns


[skJson] json (list|array) [%string%] in %jsons%
[skJson] (1:value|2:key) of json (list|array) %string% in %json%
[skJson] [value[s]] %objects% of json (list|array) [%string%]
[skJson] (1:(1st|first)|2:(2nd|second)|3:(3rd|third)|4:last|5:%integer%) element of json (list|array) [%string%]

Example


set value of json list "1::list[1]::data" in {_json} to "[]"
remove values 1 and "Hello true" of json list from {_json}
remove 2nd element of json list from {_json}
add diamond sword to json list "0::list" in {_json}
remove all "new test key" of json list "array[0]" from {_json}

2.9

Changer - JsonObject set/remove/removeAll

The new documentation you will find here: click here

A very general effect that can change many json object. The json object can be only set/remove/removeAll

Patterns


[skJson] (:key|:value)[2:s] of json object %string% in %json%
[skJson] [by] (:key|:value)[s] %objects% of json object [%string%]
[skJson] %objects% of json (object|array|list) [%string%]

Example


set value of json object "data::key" in {_json} to "new test key"
set key of json object "data::key" in {_json} to "test key"
set key of json object "list" in {_json} to "array"
set value of json object "this-a test-what i need to <>-_::data" in {_json} to iron sword
remove value "test key" of json object "data" from {_json}
remove all "new test key" of json object "data" from {_json}

2.9

Count values/elements in the Json.

You can get the number of values or keys in the given json

**Explanatory notes**:

> ``: represent a placeholder for your json e.g. `{_json}`

Patterns


[skJson] number of (0:key[s]|1:value[s]) %objects% in %json%

Example


number of keys "test" and "something" in <json>
number of key "test" in <json>

2.9.9-pre (Api change)

Get cached json

You can get json from cache storage by key defined by you

Patterns


[skJson] json [id] %string%
[skJson] all cached jsons

Example


on script load:
	set {_json} to json "your"
	send {_json} with pretty print

2.8.0 - performance & clean

Get index of key/value in ListObject

Returns the index of the key/value in the ListObject

What is ListObject? ListObject is shortcut for `[{}, {} ...]`

That means the object indexed by integer in the list

This expressions allows you found the value in the inner objects in the list.

Patterns


[skJson] index of value %object% in [object( |-)list] [%string%] of [json] %json%

2.9

Literals

Represent sort of literals for skJson

Patterns


[skJson] (1:(1st|first)|2:(2nd|second)|3:(3rd|third)|4:last|5:%integer%) element of %jsons%

Example


on script load:
	set {_json} to json from location(10,1,1)
	send first element of {_json}
	send last element of {_json}
	send 5 element of {_json}
	send 3rd element of {_json}

2.9

Loops

That will allow loop through json, and get key/index or value **json-value**, **json-key**

Patterns


[skJson] [the] json-(:value|:key)[-<(\d+)>]

Example


    on script load:
        set {_json} to json from "{'key': 'value', 'array': [1, 2, 3, false, 'index/value']}
        loop values "array" of {_json}:
            send json-value # 1, 2, 3, false, index/value
            send json-key # 1, 2, 3, 4, 5

        loop values of {_json}:
            send json-value # value, [1, 2, 3, false, "index/value"]
            send json-key # 1, 2

2.9

New json

latest:

- support now also multiple items as input

- support json content from webpage

- removed empty json array/object, cause it's not necessary while

skJson know parsing object

original docs: click here

skripthub docs:


It's allow create json from any source also from the file

Patterns


[skJson] json from [1:(text|string)|2:([json]|:yaml) file|3:web[site] [file]] [object] %objects%
[skJson] @<^(\{|\[).+(\}|\])$>

Example


on script load:
	set {_json} to json from json file "plugins/Skript/json-storage/database.json"
	set {_json::*} to json from "{'test' :true}", "B"
	set {_json} to json from diamond tools
	set {_json} to json from player's location
	set {_json} to json from player's inventory
	set {_json} to json from yaml file <path>
	set {_json} to json from website file "https://json.org/sample.json"
*Literal
set {_json} to @{"test": true, "var": {_test}}

2.9, 2.9.3 - Literal parsing

Prepare Web request

allowed methods are [GET, POST, PUT, HEAD, MOCK, DELETE, PATCH]

allowed value type of content is Json or stringify json (Json as String) e.g. "{""Test"": true}"

allowed value type of header is Json or (Pairs e.g. "Content-Type: application/Json", "Allow: restrict")

You can execute the request by 'send prepared {_request}', otherwise the request will be not sent, but the request will be still stored

And you can get response status/content/headers like in the examples

Patterns


[skJson] prepare [new] %requestmethod% [request] on %string%

Example


    set {_request} to prepare new GET request on "https://raw.githubusercontent.com/SkJsonTeam/skJson/main/skjson.jsonn"
    set {_request}'s request content to @{"A": true}
    set {_request}'s headers to @{"Content-Type": "application/json+vhd"}
    send prepared {_request}

    if response status of {_request} is "OK":
        send response content of {_request}
        send response status code of {_request}
        send response headers of {_request}

2.9.9-pre API changes

Pretty print

Allows you to better parse json

{

"test": "skJson"

"Object": {

"new": "data"

}

Patterns


[skJson] %json% with [(:uncoloured|:uncolored)] pretty print

Example


set {_json} to json from "{'test': 'skJson', 'Object' : {'new': 'data'}}"
send {_json} with pretty print
send {_json} with uncolored pretty print

2.9

Request attachment/s

set/add/reset or get the current request attachment

Patterns


[the] [request] attachments of %requests%
%requests%'[s] [request] attachments

Example


        # getting the Request attachment;
        send {_request}'s attachments
        send attachments of {_request}

        # setting the Request attachment;
        set {_request}'s attachments to attachment("*/test.sk") and attachment("*/raw.json")
        set attachments of {_request} to attachment("*/test.sk") and attachment("*/raw.json")

        # add the attachment to the Request attachments
        add attachment("*/SkJson.json") to {_request}'s attachments
        add attachment("*/SkJson.json") to attachments of {_request}

        # reset the attachments of the Request
        reset {_request}'s attachments
        reset attachments of {_request}

2.9.9-pre Api Changes

Request content

set/reset or get the current request content

Patterns


[the] [request] content of %requests%
%requests%'[s] [request] content

Example


        # getting the Request content;
        send {_request}'s content
        send content of {_request}

        # setting the Request content;
        set {_request}'s content to (json from "{'Allow': false}")
        set content of {_request} to (json from "{'Allow': false}")

        # reset the content of the Request
        reset {_request}'s content
        reset content of {_request}

2.9.9-pre Api Changes

Request headers

set or get the current request headers

Patterns


[the] [request] header[s] of %requests%
%requests%'[s] [request] header[s]

Example


        # getting the Request headers;
        send {_request}'s headers
        send headers of {_request}

        # setting the Request content;
        set {_request}'s headers to (json from "{'Content-Type': 'application/json'}")
        set headers of {_request} to (json from "{'Content-Type': 'application/json'}")

        #or
        set {_request}'s headers to "Content-Type: application/json", "Restrict: false"
        set headers of {_request} to "Content-Type: application/json", "Restrict: false"

        # reset the headers of the Request
        reset {_request}'s headers
        reset headers of {_request}

2.9.9-pre Api Changes

Request query params

set/add/reset or get the current request query params

Patterns


[the] [request] query param(s|meters) of %requests%
%requests%'[s] [request] query param(s|meters)

Example


        # getting the Request query params;
        send {_request}'s query params
        send query params of {_request}

        # setting the Request query params;
        set {_request}'s query params to "key:value", "key1:value1"
        set query params of {_request} to "key:value", "key1:value1"

        # adding the query param to the URL

        # reset the query params of the Request
        reset {_request}'s query params
        reset query params of {_request}

3.0.2

Response content, headers, status code, status

get all response properties

Patterns


[the] response [:content|:headers|:status code|:status] of %requests%
%requests%'[s] response [:content|:headers|:status code|:status]

Example


        send response status of {_request}
        send response status code of {_request}
        send response content of {_request}
        send response headers of {_request}

2.9.9-pre Api Changes

Size of json object/array

Patterns


[the] json size of %jsons%
%jsons%'[s] json size

Example


set {_json} to json from text "{'sample': {}, 'second': []}"
if json size of {_json} > 1:
	send {_json} is bigger than 1.

2.9

Skript variable to Json

Its allow convert Skript list variable to Json

Patterns


[the] form[atted json] of %jsons%
%jsons%'[s] form[atted json]

Example


on script load:
	set {_json::A::1} to false
	set {_json::A::2} to true
	set {_json::B::some} to "some great value"
	send {_json::*}'s form

1.3.0

Values of Json

Values/Key of Json

Patterns


[skJson] (0:(value %string% of %json%)|1:(values [%string%] of %json%))

Example


on script load:
	set {_json} to json from location(10,1,1)
	send values of {_json}
	send value "world" of {_json}

Checkout <b> Loops </b>

2.9

Watcher event value-expression File

value-expression for getting file/link from current watcher event

Patterns


[the] [event-](file|link)

2.9

Watcher event value-expression UUID

value-expression for getting uuid from current watcher event

Patterns


[the] [event-](uuid|id)

2.9

Change json file contents

Its allow to change directly keys/values in the given json file

Patterns


[skJson] edit (0:value|1:key) %string% of json file %string% to %object%

Example


on script load:
	new json file "plugins\SkJson\jsons\test.json"

command edit:
	trigger:
edit value "command" of json file "plugins/SkJson/jsons/test.json" to player's tool

2.8.5

Json storage

You can create virtual json in memory

Patterns


[skJson] [create] new json storage [named] %string%

Example


on script load:
	create new json storage named "json-storage"
	send json "json-storage"

2.9

Json to Skript variable list

Its allow convert Json to variable skript list

Patterns


[skJson] [:async] (map|copy) %json/string% to %objects%

Example


on script load:
	set {_json} to json from file "plugins/skript/#.json"
	map {_json} to {_json::*}

1.9, 2.9 - Support mapping json from functions

JsonWatcher - Start/Stop listening to file

You can register listener for json file, and while the file is updated the cache for this file will be also so.

Patterns


(:make|:stop) [json] watcher listen to %string%

Example


on script load
	make json watcher listen to "mine.id"
	stop json watcher listen to "mine.id"

2.8.0 - performance & clean

Link json file with defined cache.

You can works with the cache instead of reopening the file again & again.

Patterns


[skJson] link [json] file %string% as %string% [(:and make) [[json] watcher] listen]

Example


on load:
	link json file "<path to file>" as "mine.id"
	link json file "<path to file>" as "mine.id" and make json watcher listen

2.8.0 - performance & clean

New json file with-out content

Patterns


[skJson] new json file %string% [(:with) content %object%]

Example


on script load:
	new json file "plugins\SkJson\test.json"

	set {_json} to json from website "https://raw.githubusercontent.com/mozilla/node-convict/master/lerna.json"
	new json file "plugins\SkJson\test.json" with content {_json}

2.6.2

Save cached json to file

It's allow save cached json back to the file

Change syntax due Skript 2.8

Patterns


[skJson] save cached json %string%
[skJson] save all cached jsons

Example


on unload:
	save cached json "test"
	save all cached jsons

2.8.0 - performance & clean

Send created/prepared request

Send prepared/created request to the given method and uri

Patterns


[skJson] [:sync] send [prepared] %request%

Example


send prepared {_request}

2.9.9-pre Api Changes

Unlink or unload json file from cache

You can unload the json file.

Patterns


[skJson] unlink json %string%

Example


on load:
	unlink json "mine.id"

2.8.0 - performance & clean

Write content to json file

Write new data directly to json file (File will be rewritten!

Patterns


[skJson] write %object% to json file %string%

Example


on script load:
	new json file "plugins\SkJson\jsons\test.json"

command write:
	trigger:
write json from website "api-website" to json file "plugins/SkJson/jsons/test.json"

2.8.5

link and load all json files from given folder

Handle all files from folder

Patterns


[skJson] [:async] load json files from %string% and save it in %string%
[skJson] [:async] load json files from %string% and let json watcher listen to all with save it in %string%

Example


load json files from "plugins/raw/" and save it in "raw"
	loop values of json "raw":
		send json-value
*Since 2.9 [30.8.2023]*

load json files from "plugins/SkJson/jsons" and let json watcher listen to all with save in "raw"
	loop values of json "raw":
		send json-value

2.9 [30.8.2023] - add support for json watcher to all files

Json watcher save

will only run when the json watcher notices a change in the file

Patterns


[json-] watcher save

Example


on json watcher save

Event values

event-object event-object event-json

2.9

Webhook, send webhook request to Discord/Web

You can handle the discord webhooks via this section.

Can handle also embeds, Request method is PATCH/POST/PUT as always.

You can define the content, headers of each request..

Aso the request shall be sent asynchronous

You can use Json/String, also variables and functions in this section.

! Recommended read that Discord webhooks api documentation

! Recommended read that Embed generate webpage "

! Recommended default json payload Json Payload (Lorem)

Patterns


[skJson] [:async] send (:web|:discord) request %string%

Example


command web:
    trigger:
        async send web request "https://webhook.site/4e2e350b-4a8f-4863-85c5-e833e4ec110b":
            attachments:
                1: "C:\Users\nexti\Documents\Lekce\index.html"
            content: "{fromSkJson: '?', ?: true}"


command without-embed:
    trigger:
        async send discord request "https://discord.com/api/webhooks/1128075537919770798/y78NK-odks6Lod5kimmhcd9YWQfhFzPU1YA-VyD5bqWMGxaeYXxp5jTxpnNI9Yhw1Rgt":
            header: "Content-Type: application/json"
            data:
                tts: true
                content: "{'payload:' true}" # this can be any json encoded string or json


command embed:
    trigger:
        async send discord request "https://discord.com/api/webhooks/1128075537919770798/y78NK-odks6Lod5kimmhcd9YWQfhFzPU1YA-VyD5bqWMGxaeYXxp5jTxpnNI9Yhw1Rgt":
            header: "Content-Type: application/json"
            data:
                username: "AAAA"
                avatar-url: "https://google.com"
                tts: true
                content: "" # content never can be empty, so when you want to send only embed, you need to put here empty string
                embed:
                    id: 102018 # when you put here null, or auto, the value will be generated automatically.
                    fields: "{}"
                    author: "{name: 'CoffeeRequired'}"
                    title: "Hello there"
                    thumbnail: "{url: 'https://cravatar.eu/helmhead/_F0cus__/600.png'}"
                    color: "##21a7c2" # that support all hex colors.. not minecraft

command embedAtt:
    trigger:
        async send discord request "https://discord.com/api/webhooks/1128075537919770798/y78NK-odks6Lod5kimmhcd9YWQfhFzPU1YA-VyD5bqWMGxaeYXxp5jTxpnNI9Yhw1Rgt":
            attachments:
                1: "*/generate_doc.sk" # star means the parser will search for the file recursively from the root directory
            data:
                tts: false
                content: "hello from attachments"

2.9

attachment

Create new Attachment for the web request from path to file, when the file starts with */ the file will be found automatically.

Patterns


attachment(object: string)

Example


attachment("*/test.json") and attachment("*/config.sk")

2.9.9 API Changes

b64

Return base64 encoded string

Patterns


b64(object: object)

Example


serial: b64("This is a test"

2.9

getDelimiter

Return a your defined delimiter in the config.yml

Patterns


getDelimiter

Example


send "my delimiter is: %getDelimiter()%"

2.9

string

Returns string/json from base64

Patterns


string(object: object)

Example


stringify: string("dHR0dA=="

2.9.9-pre

json

JSON representation in skript

Patterns


json

2.9

json-webhook

webhooks

Patterns


json-webhook

2.9

request

Representation instance of Request

Patterns


request

2.9.9-pre API changes

This site uses cookies to provide services, personalize ads, and analyze traffic.