Skip to main content
Crowdfunding
Python + AI for Geeks
Practice

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 ,.

JSON Object Example
{
"key1": "value1",
"key2": "value2"
}

Keys are always strings enclosed in double quotes " ", and values can be strings, numbers, objects, arrays, etc.

JSON Object Example
{
"name": "John Doe",
"age": 30,
"occupation": "Developer"
}

In the JSON above:

  • name, age, occupation are keys, and John Doe, 30, Developer are their respective values.

  • The value for key name is the string "John Doe", and the value for key age is the number 30.


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.

JSON Array Example
[
"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.

Nested JSON Example
{
"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 " ".

String Example
{
"greeting": "Hello"
}

2. Number

Numbers are expressed in either integer or floating-point forms.

Number Example
{
"integer": 123,
"float": 3.14
}

3. Boolean

A Boolean can have only two values: true or false.

Boolean Example
{
"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.


Null Example
{
"phone": null
}

5. Array

An array contains multiple values in a specific order.

Array Example
{
"fruits": ["apple", "banana", "cherry"]
}

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.