JSON-like documents, standing for JavaScript Object Notation, are a way to store and transport data. They are lightweight, human-readable, and are based on a subset of the JavaScript Programming Language.
Considered as "self-describing" and easy to understand, JSON structures involve a series of unordered key-value pairs. Keys must be strings, while values can be a variety of types: strings, numbers, objects (JSON objects), arrays, booleans, or null. JSON documents and Python dictionaries are actually quite similar, both being collections of key-value pairs.
For example, let's represent a software engineer's profile using a Python dictionary that exemplifies a JSON-like document. This dictionary includes values of various types (e.g., strings, integers, lists). We store this profile in our Document-Oriented Database because this person is a stock trader interested in AI and finance.
Here's how we would represent this structure using JSON-like format which is similar to Python dictionary:
1profile = {
2 'name': 'John Doe',
3 'age': 30,
4 'profession': 'Software Engineer',
5 'languages': ['Python', 'JavaScript', 'C++'],
6 'interests': ['AI', 'Finance']
7}
To represent data hierarchically or to establish relationships among data, we might prefer JSON-like documents over tabular storage since they offer more flexibility and better readability.
xxxxxxxxxx
if __name__ == "__main__":
# Python logic here
profile = {
'name': 'John Doe',
'age': 30,
'profession': 'Software Engineer',
'languages': ['Python', 'JavaScript', 'C++'],
'interests': ['AI', 'Finance']
}
print(profile)