Working with Json within a literal has been added
as well as improved asynchronous processing for the Request class.
Example of Request
If there is a return in on complete then skjson will recognize that you want to wait for a response, RECOMMENDATION: use this only when you know the server is available.
also in on complete you can execute any code because this section is so called executable
Code (Text):
function test(i: number) :: object:
async make POST request to "http://localhost:3000/?id=%{_id}%":
save incorrect response: true
lenient: true
save:
content: {_content}
on complete:
return {_content}
local function clear():
loop 100 times:
send " " to console
command test <number>:
trigger:
loop arg-1 times:
wait 1 tick
set {_t} to test(loop-number)
send {_t}
Literal JSON
you don't need to use [code single]%[/code] before and after the expresseme because SkJson parser recognizes it and passes it to the Script parser. the same goes for strings, if you want to escape use classic json escape for example `\", \r, \t, \n"
Code (Text):
on script load:
set {_X} to @{"json": true}
set {_json} to @{id: 10, something: "Test", var: {_X}, string: "\nthis \"new\" Thing"}
send {_json}
You must enable both of these features in the settings.
Config
Code (Text):
# Beta features
features:
# That feature will you allow use tld. literal string for e.g.
# @{userId: 1, products: [{id: {_i}, quantity: 1}, {id: {_j}, quantity: 2}]}
# Inside the Literal string you don't need use a % for evaluate variables or expressions.
# Also,you don't need to use string escape as like "", you can basically json string escape for e.g.
# @{test: "This is \"New\" String"}
# So the literal start always with @ and then continue a with a JSON
literal-parsing-single-line: true
# This Feature allows you to immediately get the value from the async run of the request.
# For e.g.
# function test(i: number) :: object:
# async make POST request to "https://dummyjson.com/carts/add":
# headers: @{Content-Type: "Application/json"}
# headers: json from text "{Content-Type: 'application/json'}"
# content: json from text "{userId: 1, products: [{id: %{_i}%, quantity: 1}, {id: 50, quantity: 2}]}"
# save incorrect response: true
# lenient: true
# save:
# content: {_content}
# on complete:
# return {_content}
#
# command test <number>:
# trigger:
# send test(arg-1)
force-async-return: true
What's Changed
* Main http handing by @cooffeeRequired in https://github.com/SkJsonTeam/skJson/pull/75
* Fixed [code single]/skjson[/code] command
Full Changelog: https://github.com/SkJsonTeam/skJson/compare/2.9.1...2.9.3