<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kiai</title>
    <description>The latest articles on DEV Community by Kiai (@ningensei848).</description>
    <link>https://dev.to/ningensei848</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F749342%2Fc9e619ab-f4c4-4af7-aeb9-c1b827eb0cfe.jpeg</url>
      <title>DEV Community: Kiai</title>
      <link>https://dev.to/ningensei848</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ningensei848"/>
    <language>en</language>
    <item>
      <title>Ajv × JTD: Get Typedefs and its Validator at the Same Time</title>
      <dc:creator>Kiai</dc:creator>
      <pubDate>Thu, 11 Nov 2021 13:30:11 +0000</pubDate>
      <link>https://dev.to/ningensei848/ajv-x-jtd-get-typedefs-and-its-validator-at-the-same-time-4n9h</link>
      <guid>https://dev.to/ningensei848/ajv-x-jtd-get-typedefs-and-its-validator-at-the-same-time-4n9h</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This article has been translated from &lt;a href="https://zenn.dev/ningensei848/articles/getting-started-with-ajv-on-jtd" rel="noopener noreferrer"&gt;the original article&lt;/a&gt; by the author himself using &lt;a href="https://www.deepl.com/translator" rel="noopener noreferrer"&gt;DeepL translator&lt;/a&gt;. Thanks, &lt;a href="https://www.deepl.com/ja/publisher/" rel="noopener noreferrer"&gt;www.deepl.com&lt;/a&gt; !&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  TL; DR
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduce &lt;a href="https://ajv.js.org/" rel="noopener noreferrer"&gt;Ajv&lt;/a&gt; JSON Validator &lt;/li&gt;
&lt;li&gt;and adopt &lt;a href="https://jsontypedef.com/" rel="noopener noreferrer"&gt;JSON Typed Definition&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Cross-platform &lt;strong&gt;typed definitions&lt;/strong&gt; and &lt;strong&gt;validators&lt;/strong&gt; at your fingertips!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: This article you reading has been written with reference to &lt;a href="https://ajv.js.org/guide/getting-started.html" rel="noopener noreferrer"&gt;this page&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;It is adopted as a common standard for both the front-end and the back-end, and is universally understandable and writable by many people ―――&lt;/p&gt;

&lt;p&gt;In programming, data structures can take many forms, depending on their use; e.g. CSV / XML / YAML / TOML. While there are many examples of these, none are as widespread or as easily understood by everyone as JSON. It is often used for human reading and writing, as well as for client-server interaction.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2F4.bp.blogspot.com%2F-dVbfTZcofUU%2FVGX8crT5GiI%2FAAAAAAAApG4%2FCB7GF5UmMqE%2Fs400%2Fcomputer_cloud_system.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2F4.bp.blogspot.com%2F-dVbfTZcofUU%2FVGX8crT5GiI%2FAAAAAAAApG4%2FCB7GF5UmMqE%2Fs400%2Fcomputer_cloud_system.png" alt="a computer on a network exchanging data with a smartphone or PC"&gt;&lt;/a&gt;&lt;/p&gt;
client-server model



&lt;p&gt;On the other hand, its flexibility also makes it difficult to handle safely: When communicating with an arbitrary API server and receiving data, it's common to give up defining type of the response and treat it as &lt;code&gt;any&lt;/code&gt; type. In this way, the data can be received, but the subsequent handling will be difficult.&lt;/p&gt;

&lt;p&gt;This is when you want a &lt;em&gt;validator&lt;/em&gt;, a device that verifies and guarantees the correctness of your data. Validators can be used to detect and successfully handle property excess or deficiency and invalid values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2F4.bp.blogspot.com%2F-ZxdZh4JD7XM%2FVnE3E_EWN3I%2FAAAAAAAA1xA%2F5Zpsqd6hu0I%2Fs400%2Fjob_tantei_woman.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2F4.bp.blogspot.com%2F-ZxdZh4JD7XM%2FVnE3E_EWN3I%2FAAAAAAAA1xA%2F5Zpsqd6hu0I%2Fs400%2Fjob_tantei_woman.png" alt="Illustration of a female detective, like Sherlock Holmes, holding a magnifying glass and investigating for clues"&gt;&lt;/a&gt;&lt;/p&gt;
One truth prevails



&lt;p&gt;Of course, it's possible to code it yourself from scratch, for the sake of experience, but we'd rather use a framework that already exists ! In this article, introducing &lt;a href="https://ajv.js.org" rel="noopener noreferrer"&gt;Ajv&lt;/a&gt; as a JSON validator library for JavaScript / TypeScript. I would also show you how to define a innovative schema, called &lt;a href="https://jsontypedef.com/" rel="noopener noreferrer"&gt;JSON Typed Definition&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Note: JSON Typed Definition is proposed in &lt;a href="https://datatracker.ietf.org/doc/rfc8927/" rel="noopener noreferrer"&gt;RFC8927&lt;/a&gt; and its current status is &lt;code&gt;Experimental&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Ajv ?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkl6vdjf0kget5aq2cui9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkl6vdjf0kget5aq2cui9.png" alt="Ajv JSON schema validator | Security and reliability for JavaScript applications"&gt;&lt;/a&gt;&lt;/p&gt;
Write less code / Super fast &amp;amp; secure / Multi-standard


 

&lt;p&gt;
  read more ...
  &lt;p&gt;&lt;a href="https://ajv.js.org/" rel="noopener noreferrer"&gt;Ajv&lt;/a&gt; is a JSON validator used in a general JavaScript environment. It has the following three features :&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Write less code
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Ensure your data is valid as soon as it's received&lt;/p&gt;

&lt;p&gt;Instead of having your data validation and sanitization logic written as lengthy code, you can declare the requirements to your data with concise, easy to read and cross-platform JSON Schema or JSON Type Definition specifications and validate the data as soon as it arrives to your application.&lt;/p&gt;

&lt;p&gt;TypeScript users can use validation functions as type guards, having type level guarantee that if your data is validated - it is correct.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  2. Super fast &amp;amp; secure
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Compiles your schemas to optimized JavaScript code&lt;/p&gt;

&lt;p&gt;Ajv generates code to turn JSON Schemas into super-fast validation functions that are efficient for v8 optimization.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the early days it was very popular for its speed and rigor, but it also had many security flaws. However, over the years and with the help of many user reports, these flaws have been fixed and secure code generation has been re-established in v7.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Multi-standard
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Use JSON Type Definition or JSON Schema&lt;/p&gt;

&lt;p&gt;In addition to the multiple JSON Schema drafts, including the latest draft 2020-12, Ajv has support for JSON Type Definition - a new RFC8927 that offers a much simpler alternative to JSON Schema. &lt;br&gt;
Designed to be well-aligned with type systems, JTD has tools for both validation and type code generation for multiple languages.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;/p&gt;

&lt;h2&gt;
  
  
  Before you start with Ajv ...
&lt;/h2&gt;

&lt;p&gt;On JTD, the schema is defined using eight different &lt;em&gt;forms&lt;/em&gt; e.g. &lt;code&gt;Properties&lt;/code&gt; / &lt;code&gt;Elements&lt;/code&gt; / &lt;code&gt;Values&lt;/code&gt; etc.. If you would like to know more about these first, please see &lt;a href="https://jsontypedef.com/docs/jtd-in-5-minutes/" rel="noopener noreferrer"&gt;this article&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://jsontypedef.com/docs/jtd-in-5-minutes/" rel="noopener noreferrer"&gt;Learn JSON Typedef in 5 Minutes | JSON Typedef Docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Getting started with Ajv on JTD
&lt;/h2&gt;

&lt;p&gt;So let's get started with Ajv!&lt;/p&gt;

&lt;p&gt;First of all, we need to install the &lt;code&gt;npm&lt;/code&gt; package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;ajv
&lt;span class="c"&gt;# or&lt;/span&gt;
yarn add ajv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before you can actually validate in Ajv, you need to go through the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;define your schema on JSON Typed Definition&lt;/li&gt;
&lt;li&gt;get the type definition from the schema object by using &lt;em&gt;"utility types"&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;initialize the &lt;code&gt;Ajv()&lt;/code&gt; constructor (and do some configurations)&lt;/li&gt;
&lt;li&gt;get a validator (+

&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;α\alpha&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;α&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
) from the type definition&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's look at them in turn!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Define your schema on JSON Typed Definition
&lt;/h2&gt;

&lt;p&gt;First, here is an example of a schema definition on JSON Typed Deifinition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;int32&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;optionalProperties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some of you may have noticed &lt;code&gt;as const&lt;/code&gt; at the end of the code. This feature is called &lt;a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions" rel="noopener noreferrer"&gt;&lt;em&gt;const assertion&lt;/em&gt;&lt;/a&gt;, implemented since TypeScript 3.4.&lt;/p&gt;

&lt;p&gt;
  more descriptions ...
  &lt;p&gt;TypeScript has a feature called &lt;em&gt;type assertion&lt;/em&gt; by &lt;code&gt;as&lt;/code&gt;, which explicitly overriding an inferred type. In the case of &lt;em&gt;const assertion&lt;/em&gt;, which is an extension of &lt;em&gt;type assertion&lt;/em&gt;, it causes the following effects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Type '"hello"'&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Type '{ readonly text: "hello" }'&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Type 'readonly [10, 20]'&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Literals in expressions are not extended&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;object&lt;/em&gt; literals become (recursively all) read-only properties&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;array&lt;/em&gt; literal becomes a read-only tuple&lt;/li&gt;
&lt;/ul&gt;



&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Thanks to this feature, the schema is cast as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;int32&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;optionalProperties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All properties are now &lt;code&gt;readonly&lt;/code&gt;, and each &lt;code&gt;type&lt;/code&gt; property is now defined as a literal (&lt;code&gt;"int32"&lt;/code&gt;, &lt;code&gt;"string"&lt;/code&gt;) instead of &lt;code&gt;string;&lt;/code&gt; ! &lt;/p&gt;

&lt;h2&gt;
  
  
  2. Get the type definition from the schema object by using &lt;em&gt;"utility types"&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;Now, we have the variable &lt;code&gt;schema&lt;/code&gt;, which is type-asserted via &lt;code&gt;as const&lt;/code&gt;. What if we further apply the &lt;code&gt;typeof&lt;/code&gt; operator to this variable? It is also used in &lt;a href="https://www.typescriptlang.org/docs/handbook/2/narrowing.html#typeof-type-guards" rel="noopener noreferrer"&gt;type guards&lt;/a&gt;, which are often used to determine &lt;code&gt;undefined&lt;/code&gt;; that is, the &lt;code&gt;typeof&lt;/code&gt; operator is used to get the type of a variable &lt;code&gt;schema&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;MyData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JTDDataType&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, &lt;code&gt;typeof schema&lt;/code&gt; is passed as an argument to &lt;code&gt;JTDataType&amp;lt;T&amp;gt;&lt;/code&gt;, which is provided by the Ajv as &lt;a href="https://www.typescriptlang.org/docs/handbook/utility-types.html" rel="noopener noreferrer"&gt;&lt;em&gt;utility types&lt;/em&gt;&lt;/a&gt; . &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Utility types are types that derive another type from a type; if functions are functions in the runtime world, then utility types are functions in the type world.&lt;br&gt;
cf. &lt;a href="https://book.yyts.org/reference/type-reuse/utility-types" rel="noopener noreferrer"&gt;book.yyts.org&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is, &lt;code&gt;JTDataType&amp;lt;T&amp;gt;&lt;/code&gt; convert from the argument &lt;code&gt;typeof schema&lt;/code&gt;  to &lt;code&gt;MyData&lt;/code&gt;. At this point, this type definition has been cast as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;MyData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🤔?🤔?🤔?🤔?🤔?🤔?🤔?🤔?🤔?🤔?🤔?🤔?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnk303a2bzhp9ok63805o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnk303a2bzhp9ok63805o.png" alt="I'm sure you don't understand what I'm saying, but I don't understand it either - Jean Pierre Polnareff (JoJo's Bizarre Adventure Part 3. Stardust Crusaders)"&gt;&lt;/a&gt;&lt;/p&gt;
"I'm sure you don't understand what I am saying ..."



&lt;p&gt;＿人人人人人人人人人人人人人人人人人人＿&lt;br&gt;
＞ &lt;strong&gt;When we defined the schema in JTD,&lt;/strong&gt; ＜&lt;br&gt;
￣Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y￣&lt;/p&gt;

&lt;p&gt;＿人人人人人人人人人人人人人人人人人人人人＿&lt;br&gt;
＞ &lt;strong&gt;we also finished defining the TS typedefs!&lt;/strong&gt; ＜&lt;br&gt;
￣Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y￣&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Initialize the &lt;code&gt;Ajv()&lt;/code&gt; constructor (and do some configurations)
&lt;/h2&gt;

&lt;p&gt;Let's calm down for a moment and think about the following ...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// import Ajv from "ajv"; // &amp;lt;----- not for JTD&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Ajv&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ajv/dist/jtd&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ajv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Ajv&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we import the necessary modules and initialize the constructor. Note that the source of this import is &lt;code&gt;ajv/dist/jtd&lt;/code&gt;, since JTD is used. If you want to add more settings, you can pass &lt;a href="https://ajv.js.org/options.html#usage" rel="noopener noreferrer"&gt;Option&lt;/a&gt; as an argument to the constructor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
* For example, to report all validation errors (rather than failing on the first errors)
* you should pass allErrors option to constructor:
*/&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ajv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Ajv&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;allErrors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Get validator and +
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;α\alpha&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;α&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 from the type definition
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;compile&lt;/code&gt; constructor method can be used to convert a schema definition into a validator function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// type inference is not supported for JTDDataType yet&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;validate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ajv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;compile&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MyData&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What a surprise! 🤣 Just by defining the schema on JTD, we got a TypeScript typedef and a validator that uses it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;validData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;abc&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;validData&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// data is MyData here&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;validData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the beauty of Ajv on JTD. The amount of writing is much less, just like the goal of &lt;strong&gt;&lt;em&gt;Write less code&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;




&lt;p&gt;And there's more good news! Ajv also provide &lt;code&gt;compileParser&lt;/code&gt; and  &lt;code&gt;compileSerializer&lt;/code&gt; to meet the demand for a "more type-safe" parser and serializer. In other words, we can now do &lt;code&gt;JSON.parse()&lt;/code&gt; / &lt;code&gt;JSON.stringfy()&lt;/code&gt; in a more type-safe way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ajv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;compileParser&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MyData&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;serialize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ajv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;compileSerializer&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MyData&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;
  how to parse / serialize
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;abc&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;invalidData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;abc&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;serialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;serialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;invalidData&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// type error&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{"foo": 1, "bar": "abc"}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;invalidJson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{"unknown": "abc"}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parseAndLogFoo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// logs property&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parseAndLogFoo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;invalidJson&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// logs error and position&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;parseAndLogFoo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// MyData | undefined&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// error message from the last parse call&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;position&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// error position in string&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// data is MyData here&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;/p&gt;

&lt;p&gt;Excellent!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;JSON Typed Definition Validator&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;"OK, I'll give JTD a go!", this thought occurred to me at the end of last month. However, at the time, I had no idea how to define scheme on JSON Typed Definition. I even tried to translate &lt;a href="https://jsontypedef.com/docs/jtd-in-5-minutes/" rel="noopener noreferrer"&gt;the official explanations&lt;/a&gt; into &lt;a href="https://zenn.dev/ningensei848/articles/jtd-in-5-minutes" rel="noopener noreferrer"&gt;my native language&lt;/a&gt; to get a better understanding, but it didn't feel quite right. Or, to start with, it was bad for me because I didn't know if the schema definition was correct or not until I actually ran the code.&lt;/p&gt;

&lt;p&gt;🤮&lt;/p&gt;

&lt;p&gt;I couldn't just give up here, so I decided to build my own webApp using Next.js, which I've been working on a lot lately.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://jtd-validator.vercel.app" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstorage.googleapis.com%2Fzenn-user-upload%2F28c4a3872b4e44ea7e1d88ed.png" alt="JSON Typed Definition Validator"&gt;&lt;/a&gt;&lt;/p&gt;
Next.js + TypeScript + Mui + CodeMirror on Vercel



&lt;p&gt;Please try it! And I would love it if you gave me a star or something! 🥳&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;So far, we have actually done the following two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Schema definition based on &lt;em&gt;JSON Typed Definition&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Initial configuration of &lt;em&gt;Ajv&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here's what we got out of these:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;typedefs&lt;/strong&gt; in TypeScript derived from &lt;em&gt;JTD&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;type-safe &lt;strong&gt;&lt;em&gt;Validator&lt;/em&gt;&lt;/strong&gt; based on 1.&lt;/li&gt;
&lt;li&gt;type-safe &lt;strong&gt;&lt;em&gt;Parser&lt;/em&gt;&lt;/strong&gt; based on 1.&lt;/li&gt;
&lt;li&gt;type-safe &lt;strong&gt;&lt;em&gt;Serializer&lt;/em&gt;&lt;/strong&gt; based on 1.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2F2.bp.blogspot.com%2F-y2bo0WxJCiU%2FV4-O0nuVH0I%2FAAAAAAAA8Zc%2Flxv7lgGGBY49qw7jBMhMkQpH-sC1qfn3ACLcB%2Fs500%2Finternet_god.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2F2.bp.blogspot.com%2F-y2bo0WxJCiU%2FV4-O0nuVH0I%2FAAAAAAAA8Zc%2Flxv7lgGGBY49qw7jBMhMkQpH-sC1qfn3ACLcB%2Fs500%2Finternet_god.png" alt="Illustrations of so-called "&gt;&lt;/a&gt;&lt;/p&gt;
JSON Typed Definition brings type-safety



&lt;p&gt;Haha! After all the hard work and effort in the past, we can now get """everything""" just by defining the schema on JTD. 🥲&lt;/p&gt;

&lt;p&gt;I hope you enjoy the best schema-driven development tomorrow with  &lt;a href="https://jsontypedef.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;JSON Typed Definition&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://ajv.js.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Ajv JSON Validator&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;! 👍&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdpy2nbr6uiq9wxcn4dra.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdpy2nbr6uiq9wxcn4dra.png" alt="TypeScript × Ajv × JSON Typed Definition"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ajv</category>
      <category>jsontypeddefinition</category>
      <category>validation</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
