I heard about JSONDecode/Encode, but i don’t know how you can use it, and for what you can use it. Which is hard for me to understand, thanks for reading
I’m not a web developer, so I don’t exactly know what it’s for, but based on experience, JSONs are like tables with information. JSON is a format that allows external web services to understand the request you are making.
An example of a JSON table is this:
This is a table of your data on the forum. Not all web pages have a json, but as far as I know, most do.
JSON stands for Java Script Object Notation and it is a compact way to store data.
Adding on to all of the discussion here…
The most important part of JSON’s utility is its portability as an intermediate format.
JSON is a serialization format that defines a unified way of storing and transporting it. Because it is simply a standard format, you can find libraries to serialize to and from JSON in a variety of frameworks, languages, and environments, including but not limited to .NET, Java, Lua, and more!
Most RESTful interfaces return JSON these days, so all you have to do to read the data is grab it from its origin and deserialize it.
Lastly, JSON is human-readable and has just enough structure to be versatile for both transport and storage. You don’t need a special program to edit JSON like you do for other binary formats; just a text editor.
Could you give me an example of it’s use? Thankss
An example is when you save tables to data stores, it is serialised into JavaScript Object Notation for saving. That is why it’s usually unnecessary to encode it before saving. You would be reinventing the wheel.
When you load the data, it is deserialized for you to use it
Also if you were curious of the notation of an object in javascript…
const object = {
"hi": 5,
"bye", -5
}
Ah yes.
I’m working on a spaceship game with a user-driven market. Essentially, I want players to be able to post buy and sell orders for items in the game. In order to make a system like this, Datastore isn’t sufficient due to its restrictions on accessing, caching, and other issues.
So, I’m building my own market backend. I have a Node.js server that can take HTTP requests from Roblox, and I have it connected to a MySQL database to store the current list of market orders for each item.
I use JSON as my intermediate when I pass data from Roblox to my Node.js backend. It process goes something like this:
Roblox → HTTP Post request with a JSON body → Node.js Backend
Node.js can deserialize the data and read it. It conducts some operations, and returns a result.
Node.js Backend → HTTP response with a JSON body → Node.js Server
Why do we need to serialize? It’s because we can’t send Lua tables over the network. We can only send sequences of bytes over the network without an application-level protocol, or text with an application-level protocol. By serializing to JSON, we can convert data into a format that can be sent over the internet and is readable on the other side.
One way Roblox uses JSONs is with catalog data. I made a script in Google Sheets to get the JSON data of a hat and put it in a spreadsheet. I don’t have the script on me at the moment, but here’s an example of a catalog item’s JSON:
https://api.roblox.com/Marketplace/ProductInfo?assetId=135473949
So, for example, if in my game i have a module with my shop data (which is how im handling my shop data)
["Pets"] = {
["Doge"] = {
["Rarity"] = 1
["Cost"] = 100
}
}
This can be converted into a JSON thing? like the catalog?
read data types and syntax
“objects” are essentially lua dictionaries
also that is not required if the key name could be a valid variable name
{
Pets = {
Doge = {
Rarity = 1;
Cost = 100;
}
}
}
{"Pets":{"Doge":{"Rarity":1,"Cost":100}}}
→
{
"Pets": {
"Doge": {
"Rarity": 1,
"Cost": 100
}
}
}