SlideShare a Scribd company logo
1 of 30
Download to read offline
Proprietary + Confidential
Embracing JSON Schema
Jeremy Whitlock (@whitlockjc)
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
What is JSON Schema?
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
What is JSON Schema?
“JSON Schema is a vocabulary that allows you to
annotate and validate JSON documents.”
http://json-schema.org
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
What is JSON Schema?
“JSON Schema is a language-agnostic
description format for data structures, their
constraints and relationships.”
Jeremy Whitlock
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Simplicity Readability Language Agnostic
JSON is essentially a simple way to
represent a dict/map/… of key/value
pairs, where the values can be 1 of 6
types.
The same JSON representation is
easily consumed by humans and
machines alike.
Most languages have native support
for JSON and/or a plethora of libraries
for consuming/producing JSON.
JSON Schema
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Actual Historical Photo*
{
"message": "Ron was here!"
}
* Not really
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Description Relationships/Reuse Constraints/Validation
JSON Schema provides everything
necessary to describe data structures
regardless of their complexity.
Understanding the relationships of
more complex data structures is easy
using JSON Schema.
The same document describing your
data structures can contain
constraints that will be used by JSON
Schema libraries to do validation for
you.
JSON Schema
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema Example
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema Example
{
"title": "Submit APIStrat proposal",
"completed": true
}
TO BE CONTINUED...
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Disclaimer
All JSON Schema examples are in JSON but DO
NOT get too stuck on the JSON bit, JSON is not
required. In fact, anything that could be converted
to a JSON representation would work. For
example, YAML or a Go struct or Java Beans...
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema
{ }
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
$schema id
Used to identify the document as a
JSON Schema document, this property
value is a URL to the JSON Schema
standard your document will be using.
Used to uniquely identify your JSON
Schema document, this property value
is a URL to where your JSON Schema
document will be served. (This value
has an impact on reuse, discussed
later.)
JSON Schema - Document Metadata
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema Example
{
"$schema": "http://json-schema.org/schema#",
"id": "http://example.com/schemas/todo.json"
}
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema - Types
simple complex
● boolean
● integer*
● null
● number
● string
● array
● object
* Not a JSON type, specific to JSON Schema
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema Example
{
"$schema": "http://json-schema.org/schema#",
"id": "http://example.com/schemas/todo.json",
"type": "object"
}
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema Example
{
"$schema": "http://json-schema.org/schema#",
"id": "http://example.com/schemas/todo.json",
"type": "object",
"properties": {
"title": {
"type": "string"
},
"completed": {
"type": "boolean"
}
}
}
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema - Validation
{
"$schema": "http://json-schema.org/schema#",
"id": "http://example.com/schemas/todo.json",
"type": "object",
"properties": {
"title": {
"type": "string"
},
"completed": {
"type": "boolean"
}
}
}
{
"title": "Submit APIStrat proposal",
"completed": true
}
{}
{
"title": "Submit APIStrat proposal"
}
{
"title": "",
"completed": true,
"extra": [1, 2, 3]
}
[1, 2, 3]
{
"completed": "yes"
}
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema - Constraints and Formats
Constraints Formats
Used to apply limitations or
restrictions on the value represented in
the JSON Schema. For example,
restricting the maximum number of
characters in a string value.
Used to indicate the value is a more
specialized version of the specified
type. For example, indicating that a
string value is an email address.
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema Example
{
"$schema": "http://json-schema.org/schema#",
"id": "http://example.com/schemas/todo.json",
"type": "object",
"properties": {
"title": {
"type": "string",
"maxLength": 32
"minLength": 3
},
"completed": {
"type": "boolean"
}
},
"additionalProperties": false,
"required": ["title", "completed"]
}
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema - Validation
{
"$schema": "http://json-schema.org/schema#",
"id": "http://example.com/schemas/todo.json",
"type": "object",
"properties": {
"title": {
"type": "string",
"maxLength": 32
"minLength": 3
},
"completed": {
"type": "boolean"
}
},
"additionalProperties": false,
"required": ["title", "completed"]
}
{
"title": "Submit APIStrat proposal",
"completed": true
}
{}
{
"title": "Submit APIStrat proposal"
}
{
"title": "",
"completed": true,
"extra": [1, 2, 3]
}
[1, 2, 3]
{
"completed": "yes"
}
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema - Validation
* Not really
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema - Reuse
Composition Definitions References
Combining multiple separate schemas
into one, more complex schema.
There is a convention that if your
JSON Schema document has multiple
schemas in it, you nest them within a
root property named "definitions" and
use references to them.
Pointers to other schemas, whether in
the same document or in another
document, to avoid duplication.
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema - Definitions
The definitions property at the root
of a JSON Schema document is a
key/value pair where the key is the
human-friendly name of the schema
and the value is a schema.
{
"$schema": "http://json-schema.org/schema#",
"id": "http://example.com/schemas/todo-types.json",
"definitions": {
"Password": {
"type": "string",
// Omitted for brevity
},
"User": {
"type": "object",
// Omitted for brevity
},
"Todo": {
"type": "object",
// Omitted for brevity
}
}
}
Yes, I know comments aren't allowed in JSON...
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema - References
References are a special JSON
object that has a $ref property in it
whose value is a JSON Pointer (URI)
to another location in the same file,
another file in its entirety or specific
location within another file.
{
"$schema": "http://json-schema.org/schema#",
"id": "http://example.com/schemas/todo-items.json",
"definitions": {
"Todo": {
"type": "object",
"properties": {
"owner": {
"$ref": "person.json"
},
"created": {
"$ref": "types.json#/definitions/Timestamp"
},
// Omitted for brevity
}
},
}
"type": "array",
"items": {
"$ref": "#/definitions/Todo
},
// Omitted for brevity
}
Yes, I know comments aren't allowed in JSON...
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema - Composition
allOf ● An array of schemas
● The data must validate against all schemas
anyOf ● An array of schemas
● The data must validate against at least one schema
oneOf ● An array of schemas
● The data must validate against only one schema
not* ● A subschema
● The data must not validate against the subschema
* not is not really a composition property but it's typically documented alongside the others
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
JSON Schema - Miscellaneous
Schema Metadata Default Values
The title and description properties
can be used on any schema to give it a
human readable name and description
of what the schema represents.
Sometimes your data structures have
optional values and using a default
property allows you to fill in the gaps
when the values are not provided
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Using JSON Schema
● Code generation
● Contract enforcement
● Documentation generation
● Interface design
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Using JSON Schema - OpenAPI
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Using JSON Schema - Resources
JSON Homepage/Reference - http://www.json.org/
JSON Schema Tooling - http://json-schema.org/implementations.html
JSON Schema Homepage - http://json-schema.org/
Understanding JSON Schema Book - https://spacetelescope.github.io/understanding-json-schema/
JSON Schema Online Editor - https://jsonschema.net/#/editor
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
The End
No...I'm not really signing autographs. They wouldn't be worth the paper they are written on. ;)

More Related Content

What's hot

What's hot (20)

Xsd
XsdXsd
Xsd
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
Xml schema
Xml schemaXml schema
Xml schema
 
Javascript inside Browser (DOM)
Javascript inside Browser (DOM)Javascript inside Browser (DOM)
Javascript inside Browser (DOM)
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
Xml Lecture Notes
Xml Lecture NotesXml Lecture Notes
Xml Lecture Notes
 
Xml p5 Lecture Notes
Xml p5 Lecture NotesXml p5 Lecture Notes
Xml p5 Lecture Notes
 
Xsd tutorial
Xsd tutorialXsd tutorial
Xsd tutorial
 
Xsd examples
Xsd examplesXsd examples
Xsd examples
 
XML's validation - XML Schema
XML's validation - XML SchemaXML's validation - XML Schema
XML's validation - XML Schema
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Html (1)
Html (1)Html (1)
Html (1)
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schema
 
FFW Gabrovo PMG - HTML
FFW Gabrovo PMG - HTMLFFW Gabrovo PMG - HTML
FFW Gabrovo PMG - HTML
 
The Document Object Model
The Document Object ModelThe Document Object Model
The Document Object Model
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
 
Introduction to xml schema
Introduction to xml schemaIntroduction to xml schema
Introduction to xml schema
 
Markup Languages
Markup Languages Markup Languages
Markup Languages
 
Xml schema
Xml schemaXml schema
Xml schema
 
Web front end development introduction to html css and javascript
Web front end development introduction to html css and javascriptWeb front end development introduction to html css and javascript
Web front end development introduction to html css and javascript
 

Similar to LF_APIStrat17_Embracing JSON Schema

Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2
kriszyp
 

Similar to LF_APIStrat17_Embracing JSON Schema (20)

Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 
Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2
 
Hands on JSON
Hands on JSONHands on JSON
Hands on JSON
 
JSON-LD: JSON for the Social Web
JSON-LD: JSON for the Social WebJSON-LD: JSON for the Social Web
JSON-LD: JSON for the Social Web
 
JSON and JSON Schema in Oxygen
JSON and JSON Schema in OxygenJSON and JSON Schema in Oxygen
JSON and JSON Schema in Oxygen
 
json
jsonjson
json
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 
Json
JsonJson
Json
 
J s-o-n-120219575328402-3
J s-o-n-120219575328402-3J s-o-n-120219575328402-3
J s-o-n-120219575328402-3
 
Introduction to JSON
Introduction to JSONIntroduction to JSON
Introduction to JSON
 
Json
JsonJson
Json
 
Json at work overview and ecosystem-v2.0
Json at work   overview and ecosystem-v2.0Json at work   overview and ecosystem-v2.0
Json at work overview and ecosystem-v2.0
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examples
 
Json
JsonJson
Json
 
Json
JsonJson
Json
 
The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPress
 
Javascript2839
Javascript2839Javascript2839
Javascript2839
 
Json
JsonJson
Json
 
Elasticsearch & "PeopleSearch"
Elasticsearch & "PeopleSearch"Elasticsearch & "PeopleSearch"
Elasticsearch & "PeopleSearch"
 
AMS, API, RAILS and a developer, a Love Story
AMS, API, RAILS and a developer, a Love StoryAMS, API, RAILS and a developer, a Love Story
AMS, API, RAILS and a developer, a Love Story
 

More from LF_APIStrat

More from LF_APIStrat (20)

LF_APIStrat17_OWASP’s Latest Category: API Underprotection
LF_APIStrat17_OWASP’s Latest Category: API UnderprotectionLF_APIStrat17_OWASP’s Latest Category: API Underprotection
LF_APIStrat17_OWASP’s Latest Category: API Underprotection
 
LF_APIStrat17_Creating Communication Applications using the Asterisk RESTFul ...
LF_APIStrat17_Creating Communication Applications using the Asterisk RESTFul ...LF_APIStrat17_Creating Communication Applications using the Asterisk RESTFul ...
LF_APIStrat17_Creating Communication Applications using the Asterisk RESTFul ...
 
LF_APIStrat17_Super-Powered REST API Testing
LF_APIStrat17_Super-Powered REST API TestingLF_APIStrat17_Super-Powered REST API Testing
LF_APIStrat17_Super-Powered REST API Testing
 
LF_APIStrat17_How Mature are You? A Developer Experience Maturity Model
LF_APIStrat17_How Mature are You? A Developer Experience Maturity ModelLF_APIStrat17_How Mature are You? A Developer Experience Maturity Model
LF_APIStrat17_How Mature are You? A Developer Experience Maturity Model
 
LF_APIStrat17_Connect Your RESTful API to Hundreds of Others in Minutes (Zapi...
LF_APIStrat17_Connect Your RESTful API to Hundreds of Others in Minutes (Zapi...LF_APIStrat17_Connect Your RESTful API to Hundreds of Others in Minutes (Zapi...
LF_APIStrat17_Connect Your RESTful API to Hundreds of Others in Minutes (Zapi...
 
LF_APIStrat17_Things I Wish People Told Me About Writing Docs
LF_APIStrat17_Things I Wish People Told Me About Writing DocsLF_APIStrat17_Things I Wish People Told Me About Writing Docs
LF_APIStrat17_Things I Wish People Told Me About Writing Docs
 
LF_APIStrat17_Lifting Legacy to the Cloud on API Boosters
LF_APIStrat17_Lifting Legacy to the Cloud on API BoostersLF_APIStrat17_Lifting Legacy to the Cloud on API Boosters
LF_APIStrat17_Lifting Legacy to the Cloud on API Boosters
 
LF_APIStrat17_Contract-first API Development: A Case Study in Parallel API Pu...
LF_APIStrat17_Contract-first API Development: A Case Study in Parallel API Pu...LF_APIStrat17_Contract-first API Development: A Case Study in Parallel API Pu...
LF_APIStrat17_Contract-first API Development: A Case Study in Parallel API Pu...
 
LF_APIStrat17_Don't Repeat Yourself - Your API is Your Documentation
LF_APIStrat17_Don't Repeat Yourself - Your API is Your DocumentationLF_APIStrat17_Don't Repeat Yourself - Your API is Your Documentation
LF_APIStrat17_Don't Repeat Yourself - Your API is Your Documentation
 
LF_APIStrat17_How We Doubled the Velocity of Our Developer Experience Team
LF_APIStrat17_How We Doubled the Velocity of Our Developer Experience TeamLF_APIStrat17_How We Doubled the Velocity of Our Developer Experience Team
LF_APIStrat17_How We Doubled the Velocity of Our Developer Experience Team
 
LF_APIStrat17_API Marketing: First Comes Usability, then Discoverability
LF_APIStrat17_API Marketing: First Comes Usability, then DiscoverabilityLF_APIStrat17_API Marketing: First Comes Usability, then Discoverability
LF_APIStrat17_API Marketing: First Comes Usability, then Discoverability
 
LF_APIStrat17_Standing Taller with Technology: APIs, IoT, and the Digital Wor...
LF_APIStrat17_Standing Taller with Technology: APIs, IoT, and the Digital Wor...LF_APIStrat17_Standing Taller with Technology: APIs, IoT, and the Digital Wor...
LF_APIStrat17_Standing Taller with Technology: APIs, IoT, and the Digital Wor...
 
LF_APIStrat17_REST API Microversions
LF_APIStrat17_REST API Microversions LF_APIStrat17_REST API Microversions
LF_APIStrat17_REST API Microversions
 
LF_APIStrat17_I Believe You But My Enterprise Don't: Adopting Open Standards ...
LF_APIStrat17_I Believe You But My Enterprise Don't: Adopting Open Standards ...LF_APIStrat17_I Believe You But My Enterprise Don't: Adopting Open Standards ...
LF_APIStrat17_I Believe You But My Enterprise Don't: Adopting Open Standards ...
 
LF_APIStrat17_Case Study: Cold Decision Trees
LF_APIStrat17_Case Study: Cold Decision TreesLF_APIStrat17_Case Study: Cold Decision Trees
LF_APIStrat17_Case Study: Cold Decision Trees
 
LF_APIStrat17_Getting Your API House In Order
LF_APIStrat17_Getting Your API House In OrderLF_APIStrat17_Getting Your API House In Order
LF_APIStrat17_Getting Your API House In Order
 
LF_APIStrat17_Diving Deep into the API Ocean with Open Source Deep Learning T...
LF_APIStrat17_Diving Deep into the API Ocean with Open Source Deep Learning T...LF_APIStrat17_Diving Deep into the API Ocean with Open Source Deep Learning T...
LF_APIStrat17_Diving Deep into the API Ocean with Open Source Deep Learning T...
 
LF_APIStrat17_Supporting SDKs in 7 Different Programming Languages While Main...
LF_APIStrat17_Supporting SDKs in 7 Different Programming Languages While Main...LF_APIStrat17_Supporting SDKs in 7 Different Programming Languages While Main...
LF_APIStrat17_Supporting SDKs in 7 Different Programming Languages While Main...
 
LF_APIStrat17_Open Data vs. the World
LF_APIStrat17_Open Data vs. the World LF_APIStrat17_Open Data vs. the World
LF_APIStrat17_Open Data vs. the World
 
LF_APIStrat17_Practical DevSecOps for APIs
LF_APIStrat17_Practical DevSecOps for APIsLF_APIStrat17_Practical DevSecOps for APIs
LF_APIStrat17_Practical DevSecOps for APIs
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 

LF_APIStrat17_Embracing JSON Schema

  • 1. Proprietary + Confidential Embracing JSON Schema Jeremy Whitlock (@whitlockjc)
  • 2. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem What is JSON Schema?
  • 3. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem What is JSON Schema? “JSON Schema is a vocabulary that allows you to annotate and validate JSON documents.” http://json-schema.org
  • 4. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem What is JSON Schema? “JSON Schema is a language-agnostic description format for data structures, their constraints and relationships.” Jeremy Whitlock
  • 5. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Simplicity Readability Language Agnostic JSON is essentially a simple way to represent a dict/map/… of key/value pairs, where the values can be 1 of 6 types. The same JSON representation is easily consumed by humans and machines alike. Most languages have native support for JSON and/or a plethora of libraries for consuming/producing JSON. JSON Schema
  • 6. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Actual Historical Photo* { "message": "Ron was here!" } * Not really
  • 7. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Description Relationships/Reuse Constraints/Validation JSON Schema provides everything necessary to describe data structures regardless of their complexity. Understanding the relationships of more complex data structures is easy using JSON Schema. The same document describing your data structures can contain constraints that will be used by JSON Schema libraries to do validation for you. JSON Schema
  • 8. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema Example
  • 9. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema Example { "title": "Submit APIStrat proposal", "completed": true } TO BE CONTINUED...
  • 10. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Disclaimer All JSON Schema examples are in JSON but DO NOT get too stuck on the JSON bit, JSON is not required. In fact, anything that could be converted to a JSON representation would work. For example, YAML or a Go struct or Java Beans...
  • 11. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema { }
  • 12. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem $schema id Used to identify the document as a JSON Schema document, this property value is a URL to the JSON Schema standard your document will be using. Used to uniquely identify your JSON Schema document, this property value is a URL to where your JSON Schema document will be served. (This value has an impact on reuse, discussed later.) JSON Schema - Document Metadata
  • 13. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema Example { "$schema": "http://json-schema.org/schema#", "id": "http://example.com/schemas/todo.json" }
  • 14. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema - Types simple complex ● boolean ● integer* ● null ● number ● string ● array ● object * Not a JSON type, specific to JSON Schema
  • 15. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema Example { "$schema": "http://json-schema.org/schema#", "id": "http://example.com/schemas/todo.json", "type": "object" }
  • 16. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema Example { "$schema": "http://json-schema.org/schema#", "id": "http://example.com/schemas/todo.json", "type": "object", "properties": { "title": { "type": "string" }, "completed": { "type": "boolean" } } }
  • 17. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema - Validation { "$schema": "http://json-schema.org/schema#", "id": "http://example.com/schemas/todo.json", "type": "object", "properties": { "title": { "type": "string" }, "completed": { "type": "boolean" } } } { "title": "Submit APIStrat proposal", "completed": true } {} { "title": "Submit APIStrat proposal" } { "title": "", "completed": true, "extra": [1, 2, 3] } [1, 2, 3] { "completed": "yes" }
  • 18. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema - Constraints and Formats Constraints Formats Used to apply limitations or restrictions on the value represented in the JSON Schema. For example, restricting the maximum number of characters in a string value. Used to indicate the value is a more specialized version of the specified type. For example, indicating that a string value is an email address.
  • 19. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema Example { "$schema": "http://json-schema.org/schema#", "id": "http://example.com/schemas/todo.json", "type": "object", "properties": { "title": { "type": "string", "maxLength": 32 "minLength": 3 }, "completed": { "type": "boolean" } }, "additionalProperties": false, "required": ["title", "completed"] }
  • 20. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema - Validation { "$schema": "http://json-schema.org/schema#", "id": "http://example.com/schemas/todo.json", "type": "object", "properties": { "title": { "type": "string", "maxLength": 32 "minLength": 3 }, "completed": { "type": "boolean" } }, "additionalProperties": false, "required": ["title", "completed"] } { "title": "Submit APIStrat proposal", "completed": true } {} { "title": "Submit APIStrat proposal" } { "title": "", "completed": true, "extra": [1, 2, 3] } [1, 2, 3] { "completed": "yes" }
  • 21. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema - Validation * Not really
  • 22. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema - Reuse Composition Definitions References Combining multiple separate schemas into one, more complex schema. There is a convention that if your JSON Schema document has multiple schemas in it, you nest them within a root property named "definitions" and use references to them. Pointers to other schemas, whether in the same document or in another document, to avoid duplication.
  • 23. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema - Definitions The definitions property at the root of a JSON Schema document is a key/value pair where the key is the human-friendly name of the schema and the value is a schema. { "$schema": "http://json-schema.org/schema#", "id": "http://example.com/schemas/todo-types.json", "definitions": { "Password": { "type": "string", // Omitted for brevity }, "User": { "type": "object", // Omitted for brevity }, "Todo": { "type": "object", // Omitted for brevity } } } Yes, I know comments aren't allowed in JSON...
  • 24. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema - References References are a special JSON object that has a $ref property in it whose value is a JSON Pointer (URI) to another location in the same file, another file in its entirety or specific location within another file. { "$schema": "http://json-schema.org/schema#", "id": "http://example.com/schemas/todo-items.json", "definitions": { "Todo": { "type": "object", "properties": { "owner": { "$ref": "person.json" }, "created": { "$ref": "types.json#/definitions/Timestamp" }, // Omitted for brevity } }, } "type": "array", "items": { "$ref": "#/definitions/Todo }, // Omitted for brevity } Yes, I know comments aren't allowed in JSON...
  • 25. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema - Composition allOf ● An array of schemas ● The data must validate against all schemas anyOf ● An array of schemas ● The data must validate against at least one schema oneOf ● An array of schemas ● The data must validate against only one schema not* ● A subschema ● The data must not validate against the subschema * not is not really a composition property but it's typically documented alongside the others
  • 26. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem JSON Schema - Miscellaneous Schema Metadata Default Values The title and description properties can be used on any schema to give it a human readable name and description of what the schema represents. Sometimes your data structures have optional values and using a default property allows you to fill in the gaps when the values are not provided
  • 27. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Using JSON Schema ● Code generation ● Contract enforcement ● Documentation generation ● Interface design
  • 28. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Using JSON Schema - OpenAPI
  • 29. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem Using JSON Schema - Resources JSON Homepage/Reference - http://www.json.org/ JSON Schema Tooling - http://json-schema.org/implementations.html JSON Schema Homepage - http://json-schema.org/ Understanding JSON Schema Book - https://spacetelescope.github.io/understanding-json-schema/ JSON Schema Online Editor - https://jsonschema.net/#/editor
  • 30. Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem The End No...I'm not really signing autographs. They wouldn't be worth the paper they are written on. ;)