Hi, Batya_Cornelius !!
Think of JSON as a way to store structured data in a text format. Instead of saving data for one person in a single row of your database, you can define a text field in your database row and write data in JSON format there, allowing you to store multiple pieces of data in a single row.
With the help of ChatGPT, here’s an example of what JSON data looks like:
{
"library": [
{
"title": "The Great Journey",
"author": "F. Scott Fitzgerald",
"yearPublished": 1925,
"genre": "Adventure"
},
{
"title": "A Quiet Place",
"author": "Harper Lee",
"yearPublished": 1960,
"genre": "Fiction"
},
{
"title": "Bright Future",
"author": "George Orwell",
"yearPublished": 1949,
"genre": "Philosophical"
}
]
}
You would input this JSON data into a text field in your database. Then, if you were to retrieve this data from the database (where you would likely need to perform a text matching search on this field), you could apply filtering in your JavaScript program to the retrieved data, like this:
const testJSON = {
"library": [
{
"title": "The Great Journey",
"author": "F. Scott Fitzgerald",
"yearPublished": 1925,
"genre": "Adventure"
},
{
"title": "A Quiet Place",
"author": "Harper Lee",
"yearPublished": 1960,
"genre": "Fiction"
},
{
"title": "Bright Future",
"author": "George Orwell",
"yearPublished": 1949,
"genre": "Philosophical"
}
]
};
const specificBook = testJSON.library.find(book => book.title === "Bright Future" && book.author === "George Orwell");
console.log(specificBook); // Output the log
/*
Found data.
{
author: "George Orwell",
genre: "Philosophical",
title: "Bright Future",
yearPublished: 1949
}
*/
However, this method may lead to a decrease in performance proportional to the amount of data.