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


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

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


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

Example


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

2.8.0 - performance & clean

Json file is empty

You can check if the json file empty

Patterns


json file %string% is empty
json file %string% is(n't| not) empty

Example


Command jsonFileIsEmpty:
	trigger
		send true if json file "plugins/raw/test.json" is empty:

2.8.0 - performance & clean

Json file is listening

Check if the file for given id is listening via JsonWatcher

Patterns


[cached] json [id] %string% is listen
[cached] json [id] %string% is(n't| not) listen

Example


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

2.8.0 - performance & clean

Json has value/key

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

Patterns


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

Example


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

2.8.0 - performance & clean

Json is empty

You can check if the json empty

Patterns


json %json% is empty
json %json% is(n't| not) empty

Example


Command jsonIsEmpty
	trigger
		set {_json} to json object
		send true if {_json} is empty

2.8.0 - performance & clean

Type of json

You check json type of Json

Patterns


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

Example


on load:
	if type of {_json} is primitive:
	send true

2.8.0 - performance & clean

All cached jsons

That will return jsons from your cache.

Patterns


all cached jsons

Example


command AllCachedJsons:
	trigger:
		send all cached jsons

2.8.0 performance & clean

Array or List formatted to JSON.

It allows you to convert the sheet back to Json!

Value changes don't work for nested objects, to change the values of a nested object use Change

Patterns


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

Example


on script load:
	set {-json} to json from string "{'test': [1,2,3,false,null,'some'], 'test2': {'something': false}}"
	map {-json} to {_json::*}
	send "&9%{_json::*}'s form with pretty print%"

2.8.3 - Fix mapping for Skript beta, 1.3.0

Count of objects/phrases

You can get the exact number of identical keys or values from the entire json because `count of` works recursively.

Patterns


(count|number) of (:key|[value]) %object% in %json%

Example


set {_json} to json from string "{'A': [{'B': {}}], 'X': {}, 'UN': 'A'}"
add diamond sword to {_json} for given path "A[1]:B"
send {_json}
send count of diamond sword in {_json}
send number of key "A" in {_json}
send count of "A" in {_json}

2.8.0 performance & clean

Default changer of skJson (SET/REMOVE/ADD)

Default changer you can change your current's jsons by those expressions

More information you can found here.. : click here

Patterns


json list [%string%] in %json%
(:keys|:values) of json object [%string%] in %json%
json (:value|:key) %string% in %json%

Example


remove diamond sword from {_json}
remove 2nd element from json list "pathxys" in {_json}
remove player's location from json list "pathxys" in {_json}
remove "hello" from keys of json object "pathxys" in {_json}
remove diamond sword from values of json object "pathxys" in {_json}
set json value "test:A" in {_json} to diamond sword
add player's location to json list "pathxys" in {_json}

2.8 - b2

Elements/Values of the json

You can get the main json values, or you can also get the use values for a given object/array you can also get a single value

loop-value, loop-element, loop-key

Means : -> entries entries mean the entry for the looped element, for example we have element {"B": false}

its entry will be loop-key = B, loop-element = false, loop-value = {B=false}

!Warnings: loop-key or loop-element you can use only for entries!

LOOP-PATTERNS ->

loop-value, loop-element, loop-key

Patterns


(value|element) %string% of %object%
(values|elements) [%string%] of %object%
entr(y|ies) [%string%] of %object%

Example


command GetElements:
  trigger:
    set {_json} to json from string "{'A': [{'B': {}}, false, true, 10, 20, 22.22, 'A']}"

    # Get single element of json
    set {_single} to element "A::1" of {_json} # That will return true cause, the first element of the array "A" is true


    # Get multiple elements of json
    set {_array::*} to elements "A" of {_json} # That will return whole array so that mean ({"B": {}}, false, true, 10, 20, 22.22, A)


    # Loop through elements
    loop elements "A" of {_json}:
        send loop-value

    # loop through entries of json
    execute GET request "https://api.json.com/producs"
    loop entries of request's body:
        if loop-key = "data":
            set {_data} to element "data" of loop-element

2.8.0 performance & clean

Get cached json

You can get json from cached internal storage by with a key defined by you

Patterns


[cached] json %string%

Example


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

2.8.0 - performance & clean

Get last response

Get last response of executed request

Patterns


[SkJson] [(:current|:previous)] request's (2:body|3:code|4:connection headers|[user] (5:headers)|6:url)
[skJson] (2:body|3:code|4:connection headers|[user] (5:headers)|6:url) of [(:current|:previous)] request

Example


execute HEAD request to "https://dummyjson.com/products/1"
send body of current request with pretty print
send code of current request
send connection headers of current request
send user headers of current requestL
send url of current request

2.8.3, 2.8.0 performance & clean

Json size of given Json

Patterns


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

Example


set {_json} to json from text "{'A': 1, 'B': 2, 'C': {'A': 'B', 'X': 'Y'}}"
if json size of {_json} > 1:
	send "JSON's size is bigger the 1"

2.8.3, 2.8.0 - performance & clean

New json

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

Patterns


json[s] from [text|string] %object%
json from [(json|:yaml)] file %string%
[empty] json(-| )(0:array|1:object)

Example


set {_json} to json from file "plugins/Skript/json-storage/database.json"
set {_json} to json from "{""test"":true}"
set {_json} to json from diamond sword
set {_json} to json from player's location
set {_json} to json from player's inventory
set {_json} to json from yaml file "string"

2.8.0 - performance & clean

Pretty json

Allows you to better parse json

{

"test": "skJson"

"Object": {

"new": "data"

}

Patterns


%json% with pretty print

Example


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

2.8.0 - performance & clean

Execute a http request

You can execute a web request to rest api. with json encoded body/headers

Patterns


(execute|send|make) [new] (<.+>|%string%) request to %string% [(:with headers) %strings/json%] [and with (:body|:data) %strings/json%]
(execute|send|make) [new] (<.+>|%string%) request to %string% [with (:body|:data) %strings/json%] [and (:with headers) %strings/json%]

Example


set {_headers} to json from text "{'Content-type': 'application/json'}"
execute MOCK request to "https://dummyjson.com/http/200"
execute GET request to "https://dummyjson.com/products/ with headers "Content-type: application/json"
execute POST request to "https://dummyjson.com/products/add" with headers "Content-type: application/json" and with data "title: TEST"
send request's body with pretty print


execute GET request to "https://dummyjson.com/products/ with headers "Content-type: application/json"
if request's code is 200:
	send current request's body with pretty print

2.8.3, 2.8.0 performance & clean

JsonWatcher - Start 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 [json]watcher listen to %string%

Example


on script load
	make jsonwatcher listen to "mine.id"

2.8.0 - performance & clean

JsonWatcher - Stop listening to file

That will be stop listen file for given id

Patterns


stop [json]watcher listen to [id] %string%

Example


on script load
	stop jsonwatcher listen to id "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


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 jsonwatcher listen

2.8.0 - performance & clean

Map json to skript list

Mapping json to the List and get those values

Patterns


(map|copy) %json/string% to %objects%

Example


on load:
	set {_json} to json from string "{'test': 'test2': {}}"
	set {_json} to "{""test"": ""test2"": {}}"
	map {_json} to {_json::*}
	send {_json::*}

2.8.3 - b8210 (Fix mapping), 2.8.0 - performance & clean

New json file

You can create a new json file.

Patterns


[:async] new json file %string% [(:with) (object|content)[s] %object%]

2.8.0 - performance & clean

Save cached json to file

It's allow save cached json back to the file

Patterns


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

Example


on unload:
	save cached json "test"

2.8.0 - performance & clean

UnLink or Unload json file

You can unload the json file.

Patterns


unlink json %string%

Example


on load:
	unlink json "mine.id"

2.8.0 - performance & clean

Write json file with contents

You can write/re-write to jsons

Patterns


[re[-]]write %object% to [json file] %string/jsonfile%

Example


command sk-example:
	trigger:
		set {_json} to json from player's world
		write {_json} to json file "*.json"

2.8.0 performance & clean

change json file

You can change json file.

Patterns


[:async] change (:value|:key) %string% of (%jsonfile/string%|(:json file) %string%) to %objects%

Example


command jsonFileValue:
	trigger:
		change key "A" of jsonfile("plugins/<>/test.json") to "B"

2.8.0 - performance & clean

link and load all json files from given folder

Handle all files from folder

Patterns


load json files from %string% and save it in %string%

Example


        load json files from "plugins/raw/" and save it in "raw"
        loop entries of json "raw":
            send loop-element
        

2.8.6

jsonfile

Get json file from string/object input

Patterns


jsonfile(file: string)

Example


jsonfile("plugins/test/test.json")

2.8.0 - performance & clean

json element

Represent the json class

Patterns


json

2.8.0 - performance & clean

json file

Represent the json file class

Patterns


jsonfile

2.8.0 - performance & clean

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