Getting Started with JSON. Introducing the File Format used for… | by Niklas Lang | Jul, 2022


Introducing the File Format used for Data-Interchange

Photo by Ferenc Almasi on Unsplash

JSON is the abbreviation for the Java Script Object Notation file format. It describes a standardized data format for storing data. It is one of the text file formats because the data is stored in human-readable, natural language.

The structure of JSON files is, simply put, an unordered collection of key-value pairs. For Python programmers, this structure is best compared to the Python Dictionary.

# JavaScript Object Notation 
{
"city": "Berlin",
"country": "Germany",
"population": 3645000
}

The order of the keys “city”, “country” and “population” is not predefined, so a JSON file with a different order than that shown here will still be identical to the file displayed.

In JavaScript, objects can only have keys that are represented as strings. Since the JSON file format is derived from JavaScript, only strings can be used as keys.

The values within a pair can assume different data types. The following types are allowed:

  • String, e.g. “city”: “Berlin”.
  • Number, e.g. “population”: 3645000
  • Object, e.g. another JSON object
  • Array, e.g. “districts”: [“Kreuzberg”, “Pankow”, “Reinickendorf”]
  • Boolean, e.g. “capital”: True
  • Null

This wide variety of data types makes JSON a very popular file format. There are only a few exceptions, which cannot be stored as values in the JavaScript Object Notation.

In JSON no functions can be stored. At the same time, date formats cannot be stored natively. However, this is not a major problem, since you can store dates as strings and then convert them back to a date when reading out the file.

The use of such files is very popular due to their simplicity in structure. The requirements for the data structure are comparatively low and the files are quick and easy to understand for many users.

The widespread use can also be explained by the fact that there are now own parsers for all common programming languages, which make the use of JSON even easier.

The main drawbacks of this file format are the fuzzy number definition and the lack of standards for interpreting non-supported data types. The JavaScript Object Notation does not distinguish between common number formats, such as integer or decimal numbers. This makes the interpretation of numbers dependent on the implementation.

As already mentioned, there are some data types that are not supported by default, such as dates. This can be circumvented with the conversion to strings. However, there are different possibilities and libraries, which can be used for this and it was not agreed on any uniform standard.

JavaScript Object Notation is used in many different applications and programming languages. NoSQL and also various relational databases have connectors to store these file types.

In addition, it is also suitable for the following use cases:

  • Data transmission: When information is requested via an API, the JavaScript Object Notation is used as the response format in many cases.
  • Clear data storage: Due to the low data format requirements, flexible data structures can be stored easily.
  • Temporary data storage: The JavaScript Object Notation is also often used to store information in a program for a short time. Due to the high compatibility with other programming languages, these files can then also be used by different applications without further ado.

Python has its own library for working with JavaScript Object Notation. The corresponding file must first be opened with “open”. The stored JSON object can then be converted into an array of Python dictionaries with “load”.

# Import JSON Module 
import json
# Open file
file = open('file.json')
# parse object in Python dictionary
data_dict = json.load(file)
# Close file
file.close()
# Iterate through object
for entry in data_dict:
print(entry)
Out:
{"city": "Berlin", "country": "Germany", "population": 3645000} {"city": "Paris", "country": "France", "population": 2161000}

From now on you can work with the data in the same way as you are already used to from Python dictionaries.

  • JSON is the abbreviation for the JavaScript Object Notation file format.
  • It describes a standardized data format for storing data.
  • The file format is used for various applications because it is very easy to read and understand.
  • In addition, all common programming languages offer modules that simplify the work with JavaScript Object Notation.
  • The fuzzy number definition is the biggest disadvantage of using this file format.


Introducing the File Format used for Data-Interchange

Photo by Ferenc Almasi on Unsplash

JSON is the abbreviation for the Java Script Object Notation file format. It describes a standardized data format for storing data. It is one of the text file formats because the data is stored in human-readable, natural language.

The structure of JSON files is, simply put, an unordered collection of key-value pairs. For Python programmers, this structure is best compared to the Python Dictionary.

# JavaScript Object Notation 
{
"city": "Berlin",
"country": "Germany",
"population": 3645000
}

The order of the keys “city”, “country” and “population” is not predefined, so a JSON file with a different order than that shown here will still be identical to the file displayed.

In JavaScript, objects can only have keys that are represented as strings. Since the JSON file format is derived from JavaScript, only strings can be used as keys.

The values within a pair can assume different data types. The following types are allowed:

  • String, e.g. “city”: “Berlin”.
  • Number, e.g. “population”: 3645000
  • Object, e.g. another JSON object
  • Array, e.g. “districts”: [“Kreuzberg”, “Pankow”, “Reinickendorf”]
  • Boolean, e.g. “capital”: True
  • Null

This wide variety of data types makes JSON a very popular file format. There are only a few exceptions, which cannot be stored as values in the JavaScript Object Notation.

In JSON no functions can be stored. At the same time, date formats cannot be stored natively. However, this is not a major problem, since you can store dates as strings and then convert them back to a date when reading out the file.

The use of such files is very popular due to their simplicity in structure. The requirements for the data structure are comparatively low and the files are quick and easy to understand for many users.

The widespread use can also be explained by the fact that there are now own parsers for all common programming languages, which make the use of JSON even easier.

The main drawbacks of this file format are the fuzzy number definition and the lack of standards for interpreting non-supported data types. The JavaScript Object Notation does not distinguish between common number formats, such as integer or decimal numbers. This makes the interpretation of numbers dependent on the implementation.

As already mentioned, there are some data types that are not supported by default, such as dates. This can be circumvented with the conversion to strings. However, there are different possibilities and libraries, which can be used for this and it was not agreed on any uniform standard.

JavaScript Object Notation is used in many different applications and programming languages. NoSQL and also various relational databases have connectors to store these file types.

In addition, it is also suitable for the following use cases:

  • Data transmission: When information is requested via an API, the JavaScript Object Notation is used as the response format in many cases.
  • Clear data storage: Due to the low data format requirements, flexible data structures can be stored easily.
  • Temporary data storage: The JavaScript Object Notation is also often used to store information in a program for a short time. Due to the high compatibility with other programming languages, these files can then also be used by different applications without further ado.

Python has its own library for working with JavaScript Object Notation. The corresponding file must first be opened with “open”. The stored JSON object can then be converted into an array of Python dictionaries with “load”.

# Import JSON Module 
import json
# Open file
file = open('file.json')
# parse object in Python dictionary
data_dict = json.load(file)
# Close file
file.close()
# Iterate through object
for entry in data_dict:
print(entry)
Out:
{"city": "Berlin", "country": "Germany", "population": 3645000} {"city": "Paris", "country": "France", "population": 2161000}

From now on you can work with the data in the same way as you are already used to from Python dictionaries.

  • JSON is the abbreviation for the JavaScript Object Notation file format.
  • It describes a standardized data format for storing data.
  • The file format is used for various applications because it is very easy to read and understand.
  • In addition, all common programming languages offer modules that simplify the work with JavaScript Object Notation.
  • The fuzzy number definition is the biggest disadvantage of using this file format.

FOLLOW US ON GOOGLE NEWS

Read original article here

Denial of responsibility! Techno Blender is an automatic aggregator of the all world’s media. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials, please contact us by email – admin@technoblender.com. The content will be deleted within 24 hours.
Ai Newsartificial intelligenceFileFormatintroducingJSONJulLangmachine learningNiklasStarted
Comments (0)
Add Comment