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

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 count values in the given json

Patterns


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

Example


number of key "test" in %json%

2.9

Get cached json

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

Patterns


[skJson] json %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 key/value in the inner objects in the list.

Patterns


[skJson] [get] index of (:key|: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

loops of values/key for json

json-value, json-key

Patterns


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

Example


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

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

Pretty print

Allows you to better parse json

{

"test": "skJson"

"Object": {

"new": "data"

}

Patterns


[skJson] %jsons% 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

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

Patterns


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

Example


on unload:
	save json "test"
	save all jsons

2.8.0 - performance & clean

SkJsonStopServer

Patterns


[skJson] SkJson stop server with code [%integer%]

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


[on] [json-] watcher save [with priority (lowest|low|normal|high|highest|monitor)]

Example


on json watcher save

Event values

event-object event-json event-object

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

[WEB] Request

Create & handle requests via json

Checkout this link click here for json examples of dummyJson api

Allowed all basic types of requests [GET, POST, PUT, DELETE, PATCH, HEAD, MOCK, MODIFY, ENTRY, NOTE]

Patterns


[skJson] [:async] make [new] %requestmethod% request to %string%
[skJson] (create|make) [new] %requestmethod% request to %string% [with header[s] %json/strings% [and with body %json/strings%]] and (stored|store it) in %objects%

Example


on load:
    make new GET request to "https://dummyjson.com/products/2" and store it in {_data}:
       content: {_content}
       status code: {_code}
    execute {_data} and wait
    send {_content}


on script load:
    async make POST request to "https://dummyjson.com/carts/add":
        headers: "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

2.9.4

b64

Return base64 encoded string

Patterns


b64(object: object)

Example


serial: b64("This is a test"

2.9

skjson_getdelim

Return a your defined delimiter in the config.yml

Patterns


skjson_getdelim(bool: boolean)

Example


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

2.9

json

JSON representation in skript

Patterns


json

2.9

json-webhook

webhooks

Patterns


json-webhook

2.9

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