I don’t know of any JSON tutorials, I have not yet put one together for Bubble use. General concepts are to understand structure as simple ideas. You have Key Value Pairs like
“name” : “Roger Dodger” which is basically the Key of name and Value of Roger Dodger, just like a bubble data field is the key and the value is the value of the field in the DB.
The basic structure is every key needs to have double quotes, but not every value, as that is dependent on the type of data it is.
If the key value is supposed to be text, it needs double quotes and often is referred to as string. If the key value is supposed to be a number, there are no double quotes and is referred to as integer.
“width”: 150
To start the JSON, you have a { and to end a } with a comma between each key value pair
{
“name”: “Roger Dodger”,
“width”: 150
}
What that creates is referred to as an Object. JSON can be an array of objects, basically a list of things. To start an array of objects you use [ and end with ] and each object in the array is separated by a comma.
[
{
“name”: “Roger Dodger”,
“width”: 150
},
{
“name”: “Suzy Que”,
“width”: 215
}
]
If you want to make the most out of some of the JSON tools in Bubble you can add each array an ID key value pair, and to reference the Bubble thing keep the unique ID as a separate key value pair…but that is just if you will want to use advanced tools to do more with the JSON later.
Additionally, other data types like dates, should be stored as ISO or timestamp. ISO is better as Bubble will convert it automatically to an actual date if you will use your JSON in the API connector or something more advanced. For dates use double quotes around the value. So a dynamic expression if you are storing a date would be this things date field formatted as ISO formatted as JSON safe.
The Bubble operator of formatted as JSON safe means you do not need to use the double quotes, so something like name of Roger Dodger can be this things name formatted as JSON safe.
One thing to keep in mind, is that true to form, Bubble went half way with the formatted as JSON safe operator and didn’t make it work properly for numbers. You see, when a value is a text field, JSON safe, if it is empty will just have empty double quotes which JSON understands as an empty value. But Bubble went half way, and if the field value is a number and you use formatted as JSON safe, an empty value doesn’t show up as null as it should and so you can run into issues with JSON tools later.
Correct approach for number fields is to use an expression like this things number field is empty (yes value = null, no value = this things number field value), so that you get proper JSON for an empty number field.
For any related fields, use the related things unique ID as the value of its Key. For any option set values use the options display value formatted as JSON safe so that if you choose to do any advance use of JSON bubble will automatically pick up the correct option value.
If the field and corresponding key should be a list your JSON would be something like
“list_field“: [each items value formatted as JSON safe] when using each items value formatted as JSON safe, bubble will automatically add the double quotes and comma between each item. If you do not include the opening and closing square brackets, it will be treated as a single string value, so basically a comma separated list as one value difference being something like red, white, blue versus [red, white, blue] where the first would be one text value, and the square brackets are three text values.