Exploring JSON Data Format
When fine-tuning text-generating AI on the OpenAI platform, JSON format is required for providing training data.
In this lesson, we'll take a closer look at the JSON data format.
Structure of JSON
1. Object
An object is enclosed in 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, etc.
{
"name": "John Doe",
"age": 30,
"occupation": "Developer"
}
In the JSON above:
-
name
,age
,occupation
are keys, andJohn Doe
,30
,Developer
are their respective values. -
The value for key
name
is the string"John Doe"
, and the value for keyage
is the number30
.
2. Array
An array is enclosed in square brackets [ ]
and contains a list of values. Each value is separated by a comma. An array can include various data types such as objects, strings, numbers, etc.
[
"apple",
"cherry",
{
"product": "banana",
"price": 1000
}
]
In the JSON above, the array consists of the strings "apple"
, "cherry"
, and the object {"product": "banana", "price": 1000}
. Arrays can include diverse data types.
3. Nested Structure
JSON can have a nested structure containing objects or arrays within objects.
{
"name": "John Doe",
"contact": {
// Nested object within an object
"email": "john@example.com",
"phone": "555-1234-5678"
},
"hobbies": ["Reading", "Soccer", "Cooking"]
}
JSON Data Types
JSON supports various data types such as string, number, boolean, null, array, and object.
1. String
A string is a sequence of one or more characters enclosed in double quotes " "
.
{
"greeting": "Hello"
}
2. Number
Numbers are expressed in either integer
or floating-point
forms.
{
"integer": 123,
"float": 3.14
}
3. Boolean
A Boolean can have only two values: true
or false
.
{
"trueValue": true,
"falseValue": false
}
4. Null
Null represents a special value indicating no value
. For example, when someone's phone number is unknown, it can be represented as null
.
{
"phone": null
}
5. Array
An array contains multiple values in a specific order.
{
"fruits": ["apple", "banana", "cherry"]
}
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.