Deep Dive into JSON Data Format
When fine-tuning text generation AI developed by the OpenAI platform, the training data should be provided in JSON format.
In this lesson, we will take a closer look at the JSON data format.
Structure of JSON
1. Object
An object is enclosed with curly braces { } and consists of multiple key-value pairs.
Keys and values are separated by a colon :, and each key-value pair is separated by a comma ,.
{
"key1": "value1",
"key2": "value2"
}
Keys are always strings enclosed in double quotes " ", and values can be strings, numbers, objects, arrays, or any other supported data types.
{
"name": "John Doe",
"age": 30,
"occupation": "developer"
}
In the JSON above:
-
name,age,occupationare keys, andJohn Doe,30,developerare their values, respectively. -
The value of the key
nameis the string"John Doe", and the value for keyageis the number30.
2. Array
An array is enclosed in square brackets [ ] and contains a list of values. Each value is separated by a comma. Arrays can include objects, strings, numbers, and other data types.
[
"apple",
"cherry",
{
"product": "banana",
"price": 1000
}
]
In the JSON above, the array includes the strings "apple", "cherry", and an object {"product": "banana", "price": 1000} as its three values. Thus, arrays can include various data types.
3. Nested Structure
JSON can have nested structures containing objects within objects or arrays.
{
"name": "John Doe",
"contact": {
// Nested object within the object
"email": "john@example.com",
"phone": "555-1234"
},
"hobbies": ["reading", "soccer", "cooking"]
}
JSON Data Types
JSON supports a variety of data types including strings, numbers, booleans, null, arrays, and objects.
1. String
A string is a collection of characters enclosed in double quotes " ".
{
"string": "Hello"
}
2. Number
Numbers can be represented in both decimal and integer forms.
{
"integer": 123,
"decimal": 3.14
}
3. Boolean
A Boolean type can only have two values: true or false.
{
"trueValue": true,
"falseValue": false
}
4. Null
Null represents the special value null indicating the absence of a value. For instance, when you don't know someone's phone number, you can set the value to null.
{
"phone": null
}
5. Array
An array contains multiple values in an ordered list.
{
"fruits": ["apple", "banana", "cherry"]
}
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.