The article tells us about different types of data serializations, including YAML, JSON, and XML formats.
Serialization is the process of converting a data structure or object state to a format suitable for storage (e.g., in a file) or transmission and subsequent reconstruction (maybe in a different computer environment).
The most widely used serialization languages are:
- XML – Extensible Markup Language
- JSON – JavaScript Object Notation
- YAML – YAML Ain’t Markup Language
XML Schema
XML is a simple text-based markup language used to represent structured data such as documents, data, configurations, books, transactions, etc.
The XML schema was designed to store and transport data and to be used in a wide range of applications. Hypertext Markup Language (HTML) is similar to XML but with fewer strict rules. For details, follow the link.
XML serves as the basis for a number of standards, including the Universal Business Language (UBL), the Universal Plug and Play (UPnP) standard for home electronics, word processing formats such as ODF and OOXML, and graphics formats such as SVG. It is also supported by a number of computer programming languages and databases.
An example of using an XML schema is the pom.xml file in a Java Maven project:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javatpoint.application1</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
JSON Schema
JSON is an open standard file format and data interchange format that stores and transmits data objects composed of attribute–value pairs and arrays using human-readable text. It is a widely used data format with a variety of applications in electronic data interchange, including web applications.
JSON is known among developers as a client-server data exchange language. It is also used for creating configuration files. For details, follow the link.
JSON’s basic data types are: number, string, boolean, array, object, null.
There are several available JSON libraries for the programming languages:
Language | Library |
.NET | Json.NET |
Java | json-schema-validator |
JavaScript | JSV |
PHP | json-schema, |
Python | Jsonschema |
Ruby | ruby-jsonschema |
One of the known use cases of the JSON schema is the composer file for PHP projects:
{
"name": "company/project-example-php",
"description": "Simple PHP project",
"minimum-stability": "stable",
"version": "1.0.0",
"authors": [
{
"name": "John Doe",
"email": "john-doe@yahoo.com"
}
],
"require": {
"php": ">=7.4",
"ext-json": "*",
"ext-sockets": "*",
"symfony/process": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.2.0"
},
"autoload": {
"psr-4": {
"Company\\": "src/SimpleProject"
}
}
}
YAML Language
YAML is a human-readable data-serialization language. It is frequently used in configuration files, OpenApi (Swagger) documents and in applications that store or transmit data. For details, follow the link.
YAML is simpler than JSON. It uses brackets only for inline collections.
Below are listed some YAML libraries for the different languages:
Language | Library |
.NET | YamlDotNet |
C/C++ | yaml-cpp |
Java | snakeyaml-engine |
JavaScript | yaml |
PHP | php-yaml |
Python | ruamel.yaml |
The following are some YAML libraries for various languages:
language: php
php:
- 7.2
before-install:
- composer self-update
install:
- composer install
before_script:
- composer self-update
- composer install --prefer-source --no-interaction --dev
script:
- vendor/bin/phpunit
notifications:
email:
- john-doe@yahoo.com
Was this helpful?
0 / 0