v5.0.0
$jsonRequest
Retrieve a JSON format (api)
This function returns a property from a JSON formatted api
1
$jsonRequest[api;property;error]
Copied!
1
bot.command({
2
name: "api",
3
code: `$jsonRequest[https://some-random-api.ml/facts/dog;fact;Could not fnd a dog fact!]`
4
})
5
/*
6
​
7
API Breakdown:
8
In this api given, if you go to the link it will give you
9
{"fact":"Putting collars on dogs is an ancient practice, but dog licenses are much more recent."}
10
So in 'property', you'd put "fact", because it's the only property there to get
11
Ex:
12
$jsonRequest[https://some-random-api.ml/facts/dog;fact;Could not fnd a dog fact!]`
13
​
14
​
15
But what if the api was like this:
16
{"dog": {"fact":"Putting collars on dogs is an ancient practice, but dog licenses are much more recent."} }
17
Then in property, first you'd
18
need to get "dog", so you'd put 'dog', then to get the fact
19
add fact after it, like this: 'dog.fact'
20
Ex:
21
$jsonRequest[https://some-random-api.ml/facts/dog;dog.fact;Could not fnd a dog fact!]`
22
​
23
​
24
But let's say the api has brackets around the thing you
25
want to get:
26
{"dog": [{"fact":"Putting collars on dogs is an ancient practice, but dog licenses are much more recent."}] }
27
So in property, you will still have 'dog' first,
28
then you'd add brackets as follows: 'dog[0]'
29
then simply add on fact. 'dog[0].fact'
30
WARNING: For DBD.js instead of [] we use #RIGHT# for [ and #LEFT# for ]
31
Ex:
32
$jsonRequest[https://some-random-api.ml/facts/dog;dog#RIGHT#0#LEFT#.fact;Could not fnd a dog fact!]`
33
​
34
​
35
*/
Copied!
Last modified 1mo ago
Copy link
Edit on GitHub