SlideShare a Scribd company logo
1 of 39
Download to read offline
Hands on
JSON
© 2019 Syncro Soft SRL. All rights reserved.
Octavian Nadolu, Syncro Soft
octavian_nadolu@oxygenxml.com
@OctavianNadolu
Hands on JSON
Software Architect at Syncro Soft
octavian.nadolu@oxygenxml.com
• 15+ years of XML technology experience
• Contributor for various XML-related open source projects
• Editor of Schematron QuickFix specification developed by a W3C
community group
About me
Hands on JSON
Agenda
●
JSON Documents Structure
●
Validating JSON Documents
●
Querying and Transforming JSON Documents
●
Converting JSON Documents
Hands on JSON
JSON
(JavaScript Object Notation)
●
Data representation format
●
Used for API and Configs
●
Lightweight and easy to read/write
http://json.org
Hands on JSON
JSON Documents Structure
●
JSON Data – name/value pair
●
JSON Object {...}
●
JSON Array [...]
Hands on JSON
JSON Data
●
A collection of name/value pairs
●
The name in double quotes, followed by a colon, followed by a value
”firstname”: ”Jane”
Hands on JSON
Value
{...}, [...], 2, "one", true, null
Hands on JSON
Object
{”firstname”: ”Jane”, ”lastname": ”Doe”}
Hands on JSON
Array
[{”firstname”: ”Jane”, ”lastname": ”Doe”},
{”firstname”: ”John”, ”lastname": ”Jones”}]
Hands on JSON
Example
{
"persons": [
{
"id": "jane.doe",
"firstname": "Jane",
"lastname": "Doe",
"email": "jane@oxygenxml.com",
"age": 37
},
{
"id": "john.jones",
"firtname": "John",
"lastname": "Jones",
"email": "john@oxygenxml.com",
"age": 42
}
]
}
Object
Array
Property
Value
Hands on JSON
Validating JSON Documents
●
Checking Well-Formedness in JSON
Documents
●
Validating JSON Documents Against JSON
Schema
●
Validating JSON Schema According to the
Specification
Hands on JSON
Checking Well-Formedness
Check if the JSON document respects the JSON specification
{
"id": "jane.doe",
"firstname": "Jane",
"lastname": "Doe",
"email": "jane@oxygenxml.com",
"age": 37
}
ECMA-404 The JSON Data Interchange Standard
http://json.org/
Hands on JSON
Example
{
"persons" [
{
"id": "jane.doe",
"firstname": "Jane",
"lastname": "Doe",
"email": "jane@oxygenxml.com"
"age": 37,
},
{
"id": "john.jones,
"firtname": "John",
"lastname": "Jones",
"email": "john@oxygenxml.com",
"age": 42
]
}
Expected ',' character
Unexpected ',' character
Expected a ':' after a key
Expected quotes
Expected '}'
Hands on JSON
JSON Schema
JSON Schema is a vocabulary that
allows you to annotate and validate
JSON documents
http://json-schema.org
Hands on JSON
Defining JSON Schema
●
Similar to XML Schema, RNG, or DTD
●
Written in JSON
●
Used to define the structure of a JSON data
{”type”: ”string”}
JSON Schema
”I'm a string”
JSON Instance
Hands on JSON
Example
JSON Schema
{
"type": "object",
"properties": {
"persons": {
"type": "array"
}
}
}
JSON Instance
{
"persons": [ ]
}
Hands on JSON
Example
JSON Schema
{
"type": "object",
"properties": {
"persons": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {"type": "string"},
"firstname": {"type": "string"},
"lastname": {"type": "string"},
"email": {"type": "string","format": "email"},
"age": {"type": "number"}
}
}
}
}
}
JSON Instance
{
"persons": [
{
"id": "jane.doe",
"firstname": "Jane",
"lastname": "Doe",
"email": "jane@oxygenxml.com",
"age": 37}
]
}
Hands on JSON
JSON Schema Definition
●
It is recommended to to have the schema definition on the
first level
"$schema": "http://json-schema.org/draft-07/schema#"
●
JSON Schema used versions:
– Draft 4
– Draft 6
– Draft 7
– Draft 8
Hands on JSON
Validating with JSON Schema
●
Check if the JSON instance respects the definitions
{
"persons": [
{
"id": 2,
"firstname": "Jane",
"familyname": "Doe",
"email": "jane@oxygenxml..com",
"age": 37
}
]
}
Invalid email address
Expected string, but fund integer
Required key [lastname] not found
[familyname] is not permitted
Hands on JSON
Associate JSON Schema
●
Associating a Schema to JSON Documents
– Directly in JSON document – using $schema property
– In application options
{
"$schema": "person-schema.json",
"persons" [ ... ]
}
Absolute or relative URI
Hands on JSON
Validating JSON Schema
●
Check for well-formedness
●
Validate accordingly to the Internet Engineering Task Force
(IETF) Specification
Hands on JSON
Validating JSON with Schematron
●
Specify the JSON structure using JSON Schema
●
Express co-constraints and define custom rules using
Schematron
Hands on JSON
Schematron for JSON
●
Use XPath to express the rules
<sch:rule context="persons">
<sch:assert test="number(age) > preceding-sibling::node()/age ">
The person age must be grater than the previous person age </sch:assert>
</sch:rule>
Hands on JSON
Schematron using JSONPath
●
Schematron reimagined for JSON with no whiff of
XML/XPath
●
Moved out of the XPath and use JSONPath
https://github.com/amer-ali/jsontron
"rule": [
{"context": "$.persons.*",
"assert": [
{"test": "(jp.query(contextNode,'$..age') >= 21",
"message": "The person age must be grater than 21"}
]
}
]
Hands on JSON
Querying and Transforming
●
Query using JSON Pointer,
JSONiq, or XPath
●
Transform JSON using
JavaScript, XSLT, XQuery
Hands on JSON
JSON Pointer
Used to identify a specific value within a JSON document
#/persons/0/email
Matches first person email
Specification
https://tools.ietf.org/html/rfc6901
Hands on JSON
JSONiq
A query and processing language for JSON
www.jsoniq.org
Hands on JSON
XPath
●
Powerful language for queering XML documents
●
Was adopted by applications also for JSON
/persons[2]/email
Matches second person email
Hands on JSON
Process JSON with JavaScript
●
Most popular way to process JSON documents
●
Multiple libraries
var json = '{"name":”John Doe”, "age":42}';
obj = JSON.parse(json);
console.log(obj.name); // Result John Doe
console.log(obj.age); // Result 42
Hands on JSON
Transform using XSLT/XQuery
●
Transform JSON Documents to Different Formats
●
Different functions to process JSON document:
●
json-doc($href as xs:string?) as item()?
●
json-to-xml($json-text as xs:string?) as document-node()?
Hands on JSON
Converting JSON Documents
●
JSON to XML and XML to JSON
●
Convert using XSLT
●
Online Converters
Hands on JSON
JSON to XML
{
"personnel": {
"person": [
{
"id": 1,
"name": {
"family": "Worker",
"given": "One"
},
"email": "one@oxygenxml.com",
"link": {"manager": "Big.Boss"}
},
{
"id": 2,
"name": {
"family": "Worker",
"given": "Two"
},
"email": "two@oxygenxml.com",
"link": {"manager": "Big.Boss"}
}
]
}
}
<personnel>
<person>
<id>1</id>
<name>
<family>Worker</family>
<given>One</given>
</name>
<email>one@oxygenxml.com</email>
<link>
<manager>Big.Boss</manager>
</link>
</person>
<person>
<id>2</id>
<name>
<family>Worker</family>
<given>Two</given>
</name>
<email>two@oxygenxml.com</email>
<link>
<manager>Big.Boss</manager>
</link>
</person>
</personnel>
Hands on JSON
JSON to XML Conversion Details
●
A <JSON> element is added as root if the converted JSON
has multiple properties on the first level
●
An <array> element is added as root if the converted JSON is
an array
[
{"name": "Boss"},
{"name": "Worker"}
]
<array>
<array>
<name>Boss</name>
</array>
<array>
<name>Worker</name>
</array>
</array>
{
"person": "one",
"id": "personnel-id"
}
<JSON>
<person>one</person>
<id>personnel-id</id>
</JSON>
Hands on JSON
1
XML to JSON
<personnel>
<person id="1">
<name>
<family>Worker</family>
<given>One</given>
</name>
<email>one@oxygenxml.com</email>
<link manager="harris.anderson"/>
</person>
<person>
<id>2</id>
<name>
<family>Worker</family>
<given>Two</given>
</name>
<email>two@oxygenxml.com</email>
<link manager="harris.anderson"/>
</person>
</personnel>
{
"personnel": {
"person": [
{
"id": 1,
"name": {
"family": "Worker",
"given": "One"
},
"email": "one@oxygenxml.com",
"link": {"manager": "harris.anderson"}
},
{
"id": 2,
"name": {
"family": "Worker",
"given": "Two"
},
"email": "two@oxygenxml.com",
"link": {"manager": "harris.anderson"}
}
]
}
}
Hands on JSON
XML to JSON Conversion Details
●
XML attributes are converted to properties
<person id="1"/> {"person": {"id": 1}}
●
Multiple elements with the same name are converted into
an array
<person/> <person/> "person": ["",""]
●
Text in mixed content will be converted in a #text property
<p>This is an <b>example</b>!</p> p": {"#text": "This is an","b": "example","#text1": "!"}
Hands on JSON
Convert using XSLT
●
Library that converts XML to JSON using XSLT
https://github.com/bramstein/xsltjson
XSLT Specification for JSON
http://www.w3.org/TR/xslt-30/#json
Hands on JSON
Online Converter
●
Online XML to JSON Converters
Convert between XML and JSON
Hands on JSON
Conclusion
●
JSON conforms to ECMA/ISO specification
●
Validate JSON with JSON Schema
●
Query and process JSON using JSON Pointer, JSONiq, XPath,
or JavaScript and XSLT
●
Conversions to convert between JSON and XML
Questions?
Octavian Nadolu
Software Architect at Syncro Soft
octavian.nadolu@oxygenxml.com
Twitter: @OctavianNadolu
LinkedIn: octaviannadolu
https://sundt01.honestly.de

More Related Content

What's hot

Atomicity In Redis: Thomas Hunter
Atomicity In Redis: Thomas HunterAtomicity In Redis: Thomas Hunter
Atomicity In Redis: Thomas HunterRedis Labs
 
Introduction to Prometheus
Introduction to PrometheusIntroduction to Prometheus
Introduction to PrometheusJulien Pivotto
 
Real Time Test Data with Grafana
Real Time Test Data with GrafanaReal Time Test Data with Grafana
Real Time Test Data with GrafanaIoannis Papadakis
 
Présentation de Robot framework
Présentation de Robot frameworkPrésentation de Robot framework
Présentation de Robot frameworkgilleslenfant
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST APIFabien Vauchelles
 
Low Code Integration with Apache Camel.pdf
Low Code Integration with Apache Camel.pdfLow Code Integration with Apache Camel.pdf
Low Code Integration with Apache Camel.pdfClaus Ibsen
 
An Intro to Atom Editor
An Intro to Atom EditorAn Intro to Atom Editor
An Intro to Atom EditorAteev Chopra
 
Google Chrome DevTools features overview
Google Chrome DevTools features overviewGoogle Chrome DevTools features overview
Google Chrome DevTools features overviewOleksii Prohonnyi
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsSashko Stubailo
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDBvaluebound
 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Mindfire Solutions
 
Web automation using selenium.ppt
Web automation using selenium.pptWeb automation using selenium.ppt
Web automation using selenium.pptAna Sarbescu
 
Introduction to Web Development
Introduction to Web DevelopmentIntroduction to Web Development
Introduction to Web DevelopmentParvez Mahbub
 
High Performance WordPress
High Performance WordPressHigh Performance WordPress
High Performance WordPressvnsavage
 
Nakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - EnglishNakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - EnglishSvetlin Nakov
 
Experience lessons from architecture of zalo real time system
Experience lessons from architecture of zalo real time systemExperience lessons from architecture of zalo real time system
Experience lessons from architecture of zalo real time systemZalo_app
 

What's hot (20)

Istio presentation jhug
Istio presentation jhugIstio presentation jhug
Istio presentation jhug
 
Atomicity In Redis: Thomas Hunter
Atomicity In Redis: Thomas HunterAtomicity In Redis: Thomas Hunter
Atomicity In Redis: Thomas Hunter
 
Introduction to Prometheus
Introduction to PrometheusIntroduction to Prometheus
Introduction to Prometheus
 
Real Time Test Data with Grafana
Real Time Test Data with GrafanaReal Time Test Data with Grafana
Real Time Test Data with Grafana
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
Présentation de Robot framework
Présentation de Robot frameworkPrésentation de Robot framework
Présentation de Robot framework
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
 
Low Code Integration with Apache Camel.pdf
Low Code Integration with Apache Camel.pdfLow Code Integration with Apache Camel.pdf
Low Code Integration with Apache Camel.pdf
 
An Intro to Atom Editor
An Intro to Atom EditorAn Intro to Atom Editor
An Intro to Atom Editor
 
Google Chrome DevTools features overview
Google Chrome DevTools features overviewGoogle Chrome DevTools features overview
Google Chrome DevTools features overview
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer tools
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)
 
Web automation using selenium.ppt
Web automation using selenium.pptWeb automation using selenium.ppt
Web automation using selenium.ppt
 
Introduction to Web Development
Introduction to Web DevelopmentIntroduction to Web Development
Introduction to Web Development
 
High Performance WordPress
High Performance WordPressHigh Performance WordPress
High Performance WordPress
 
Nakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - EnglishNakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - English
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Experience lessons from architecture of zalo real time system
Experience lessons from architecture of zalo real time systemExperience lessons from architecture of zalo real time system
Experience lessons from architecture of zalo real time system
 

Similar to Hands on JSON: Validate, Query, Transform and Convert JSON Documents

JSON and JSON Schema in Oxygen
JSON and JSON Schema in OxygenJSON and JSON Schema in Oxygen
JSON and JSON Schema in OxygenOctavian Nadolu
 
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)Skillwise Group
 
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 examplesSanjeev Kumar Jaiswal
 
JSON - JavaScript Object Notation
JSON - JavaScript Object NotationJSON - JavaScript Object Notation
JSON - JavaScript Object NotationSothearin Ren
 
LF_APIStrat17_Embracing JSON Schema
LF_APIStrat17_Embracing JSON SchemaLF_APIStrat17_Embracing JSON Schema
LF_APIStrat17_Embracing JSON SchemaLF_APIStrat
 
Devoxx - JSON Validation using JSON Schema and Jackson
Devoxx - JSON Validation using JSON Schema and JacksonDevoxx - JSON Validation using JSON Schema and Jackson
Devoxx - JSON Validation using JSON Schema and Jacksonsrondal
 
JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12Jitendra Zaa
 
Writing Domain Specific Languages with JSON Schema
Writing Domain Specific Languages with JSON SchemaWriting Domain Specific Languages with JSON Schema
Writing Domain Specific Languages with JSON SchemaYos Riady
 
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 2kriszyp
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problemstitanlambda
 

Similar to Hands on JSON: Validate, Query, Transform and Convert JSON Documents (20)

Json
JsonJson
Json
 
JSON and JSON Schema in Oxygen
JSON and JSON Schema in OxygenJSON and JSON Schema in Oxygen
JSON and JSON Schema in Oxygen
 
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)
 
Introduction to JSON
Introduction to JSONIntroduction to JSON
Introduction to JSON
 
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
 
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 - JavaScript Object Notation
JSON - JavaScript Object NotationJSON - JavaScript Object Notation
JSON - JavaScript Object Notation
 
LF_APIStrat17_Embracing JSON Schema
LF_APIStrat17_Embracing JSON SchemaLF_APIStrat17_Embracing JSON Schema
LF_APIStrat17_Embracing JSON Schema
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 
java script json
java script jsonjava script json
java script json
 
Devoxx - JSON Validation using JSON Schema and Jackson
Devoxx - JSON Validation using JSON Schema and JacksonDevoxx - JSON Validation using JSON Schema and Jackson
Devoxx - JSON Validation using JSON Schema and Jackson
 
JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12
 
Writing Domain Specific Languages with JSON Schema
Writing Domain Specific Languages with JSON SchemaWriting Domain Specific Languages with JSON Schema
Writing Domain Specific Languages with JSON Schema
 
Json
JsonJson
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
 
Working with JSON
Working with JSONWorking with JSON
Working with JSON
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problems
 

More from Octavian Nadolu

YAML Editing and Validation In Oxygen
YAML Editing and Validation In OxygenYAML Editing and Validation In Oxygen
YAML Editing and Validation In OxygenOctavian Nadolu
 
Leveraging the Power of AI and Schematron for Content Verification and Correc...
Leveraging the Power of AI and Schematron for Content Verification and Correc...Leveraging the Power of AI and Schematron for Content Verification and Correc...
Leveraging the Power of AI and Schematron for Content Verification and Correc...Octavian Nadolu
 
OpenAPI/AsyncAPI Support in Oxygen
OpenAPI/AsyncAPI Support in OxygenOpenAPI/AsyncAPI Support in Oxygen
OpenAPI/AsyncAPI Support in OxygenOctavian Nadolu
 
Validating XML and JSON Documents Using Oxygen Scripting
 Validating XML and JSON Documents Using Oxygen Scripting Validating XML and JSON Documents Using Oxygen Scripting
Validating XML and JSON Documents Using Oxygen ScriptingOctavian Nadolu
 
OpenAPI Editing, Testing, and Documenting
OpenAPI Editing, Testing, and DocumentingOpenAPI Editing, Testing, and Documenting
OpenAPI Editing, Testing, and DocumentingOctavian Nadolu
 
JSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPIJSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPIOctavian Nadolu
 
Create an Design JSON Schema
Create an Design JSON SchemaCreate an Design JSON Schema
Create an Design JSON SchemaOctavian Nadolu
 
Compare And Merge Scripts
Compare And Merge ScriptsCompare And Merge Scripts
Compare And Merge ScriptsOctavian Nadolu
 
Schematron For Non-XML Languages
Schematron For Non-XML LanguagesSchematron For Non-XML Languages
Schematron For Non-XML LanguagesOctavian Nadolu
 
HTML5 Editing Validation
HTML5 Editing ValidationHTML5 Editing Validation
HTML5 Editing ValidationOctavian Nadolu
 
Documentation Quality Assurance with ISO Schematron
Documentation Quality Assurance with ISO SchematronDocumentation Quality Assurance with ISO Schematron
Documentation Quality Assurance with ISO SchematronOctavian Nadolu
 
Introduction to Schematron
Introduction to SchematronIntroduction to Schematron
Introduction to SchematronOctavian Nadolu
 
JSON Edit, Validate, Query, Transform, and Convert
JSON Edit, Validate, Query, Transform, and ConvertJSON Edit, Validate, Query, Transform, and Convert
JSON Edit, Validate, Query, Transform, and ConvertOctavian Nadolu
 
The Power Of Schematron Quick Fixes - XML Prague 2019
The Power Of Schematron Quick Fixes - XML Prague 2019The Power Of Schematron Quick Fixes - XML Prague 2019
The Power Of Schematron Quick Fixes - XML Prague 2019Octavian Nadolu
 
Collaboration Tools to Help Improve Documentation Process
Collaboration Tools to Help Improve Documentation ProcessCollaboration Tools to Help Improve Documentation Process
Collaboration Tools to Help Improve Documentation ProcessOctavian Nadolu
 
Exploring the new features in Oxygen XML Editor 20 - Development
Exploring the new features in Oxygen XML Editor 20 - DevelopmentExploring the new features in Oxygen XML Editor 20 - Development
Exploring the new features in Oxygen XML Editor 20 - DevelopmentOctavian Nadolu
 
Comparing and Merging XML Documents in Visual Mode
Comparing and Merging XML Documents in Visual ModeComparing and Merging XML Documents in Visual Mode
Comparing and Merging XML Documents in Visual ModeOctavian Nadolu
 

More from Octavian Nadolu (20)

YAML Editing and Validation In Oxygen
YAML Editing and Validation In OxygenYAML Editing and Validation In Oxygen
YAML Editing and Validation In Oxygen
 
Oxygen JSON Editor
Oxygen JSON EditorOxygen JSON Editor
Oxygen JSON Editor
 
Leveraging the Power of AI and Schematron for Content Verification and Correc...
Leveraging the Power of AI and Schematron for Content Verification and Correc...Leveraging the Power of AI and Schematron for Content Verification and Correc...
Leveraging the Power of AI and Schematron for Content Verification and Correc...
 
OpenAPI/AsyncAPI Support in Oxygen
OpenAPI/AsyncAPI Support in OxygenOpenAPI/AsyncAPI Support in Oxygen
OpenAPI/AsyncAPI Support in Oxygen
 
Validating XML and JSON Documents Using Oxygen Scripting
 Validating XML and JSON Documents Using Oxygen Scripting Validating XML and JSON Documents Using Oxygen Scripting
Validating XML and JSON Documents Using Oxygen Scripting
 
OpenAPI Editing, Testing, and Documenting
OpenAPI Editing, Testing, and DocumentingOpenAPI Editing, Testing, and Documenting
OpenAPI Editing, Testing, and Documenting
 
JSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPIJSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPI
 
Create an Design JSON Schema
Create an Design JSON SchemaCreate an Design JSON Schema
Create an Design JSON Schema
 
Compare And Merge Scripts
Compare And Merge ScriptsCompare And Merge Scripts
Compare And Merge Scripts
 
JSON Schema Design
JSON Schema DesignJSON Schema Design
JSON Schema Design
 
Schematron For Non-XML Languages
Schematron For Non-XML LanguagesSchematron For Non-XML Languages
Schematron For Non-XML Languages
 
HTML5 Editing Validation
HTML5 Editing ValidationHTML5 Editing Validation
HTML5 Editing Validation
 
Documentation Quality Assurance with ISO Schematron
Documentation Quality Assurance with ISO SchematronDocumentation Quality Assurance with ISO Schematron
Documentation Quality Assurance with ISO Schematron
 
Introduction to Schematron
Introduction to SchematronIntroduction to Schematron
Introduction to Schematron
 
JSON Edit, Validate, Query, Transform, and Convert
JSON Edit, Validate, Query, Transform, and ConvertJSON Edit, Validate, Query, Transform, and Convert
JSON Edit, Validate, Query, Transform, and Convert
 
The Power Of Schematron Quick Fixes - XML Prague 2019
The Power Of Schematron Quick Fixes - XML Prague 2019The Power Of Schematron Quick Fixes - XML Prague 2019
The Power Of Schematron Quick Fixes - XML Prague 2019
 
Collaboration Tools to Help Improve Documentation Process
Collaboration Tools to Help Improve Documentation ProcessCollaboration Tools to Help Improve Documentation Process
Collaboration Tools to Help Improve Documentation Process
 
Schematron step-by-step
Schematron step-by-stepSchematron step-by-step
Schematron step-by-step
 
Exploring the new features in Oxygen XML Editor 20 - Development
Exploring the new features in Oxygen XML Editor 20 - DevelopmentExploring the new features in Oxygen XML Editor 20 - Development
Exploring the new features in Oxygen XML Editor 20 - Development
 
Comparing and Merging XML Documents in Visual Mode
Comparing and Merging XML Documents in Visual ModeComparing and Merging XML Documents in Visual Mode
Comparing and Merging XML Documents in Visual Mode
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

Hands on JSON: Validate, Query, Transform and Convert JSON Documents

  • 1. Hands on JSON © 2019 Syncro Soft SRL. All rights reserved. Octavian Nadolu, Syncro Soft octavian_nadolu@oxygenxml.com @OctavianNadolu
  • 2. Hands on JSON Software Architect at Syncro Soft octavian.nadolu@oxygenxml.com • 15+ years of XML technology experience • Contributor for various XML-related open source projects • Editor of Schematron QuickFix specification developed by a W3C community group About me
  • 3. Hands on JSON Agenda ● JSON Documents Structure ● Validating JSON Documents ● Querying and Transforming JSON Documents ● Converting JSON Documents
  • 4. Hands on JSON JSON (JavaScript Object Notation) ● Data representation format ● Used for API and Configs ● Lightweight and easy to read/write http://json.org
  • 5. Hands on JSON JSON Documents Structure ● JSON Data – name/value pair ● JSON Object {...} ● JSON Array [...]
  • 6. Hands on JSON JSON Data ● A collection of name/value pairs ● The name in double quotes, followed by a colon, followed by a value ”firstname”: ”Jane”
  • 7. Hands on JSON Value {...}, [...], 2, "one", true, null
  • 8. Hands on JSON Object {”firstname”: ”Jane”, ”lastname": ”Doe”}
  • 9. Hands on JSON Array [{”firstname”: ”Jane”, ”lastname": ”Doe”}, {”firstname”: ”John”, ”lastname": ”Jones”}]
  • 10. Hands on JSON Example { "persons": [ { "id": "jane.doe", "firstname": "Jane", "lastname": "Doe", "email": "jane@oxygenxml.com", "age": 37 }, { "id": "john.jones", "firtname": "John", "lastname": "Jones", "email": "john@oxygenxml.com", "age": 42 } ] } Object Array Property Value
  • 11. Hands on JSON Validating JSON Documents ● Checking Well-Formedness in JSON Documents ● Validating JSON Documents Against JSON Schema ● Validating JSON Schema According to the Specification
  • 12. Hands on JSON Checking Well-Formedness Check if the JSON document respects the JSON specification { "id": "jane.doe", "firstname": "Jane", "lastname": "Doe", "email": "jane@oxygenxml.com", "age": 37 } ECMA-404 The JSON Data Interchange Standard http://json.org/
  • 13. Hands on JSON Example { "persons" [ { "id": "jane.doe", "firstname": "Jane", "lastname": "Doe", "email": "jane@oxygenxml.com" "age": 37, }, { "id": "john.jones, "firtname": "John", "lastname": "Jones", "email": "john@oxygenxml.com", "age": 42 ] } Expected ',' character Unexpected ',' character Expected a ':' after a key Expected quotes Expected '}'
  • 14. Hands on JSON JSON Schema JSON Schema is a vocabulary that allows you to annotate and validate JSON documents http://json-schema.org
  • 15. Hands on JSON Defining JSON Schema ● Similar to XML Schema, RNG, or DTD ● Written in JSON ● Used to define the structure of a JSON data {”type”: ”string”} JSON Schema ”I'm a string” JSON Instance
  • 16. Hands on JSON Example JSON Schema { "type": "object", "properties": { "persons": { "type": "array" } } } JSON Instance { "persons": [ ] }
  • 17. Hands on JSON Example JSON Schema { "type": "object", "properties": { "persons": { "type": "array", "items": { "type": "object", "properties": { "id": {"type": "string"}, "firstname": {"type": "string"}, "lastname": {"type": "string"}, "email": {"type": "string","format": "email"}, "age": {"type": "number"} } } } } } JSON Instance { "persons": [ { "id": "jane.doe", "firstname": "Jane", "lastname": "Doe", "email": "jane@oxygenxml.com", "age": 37} ] }
  • 18. Hands on JSON JSON Schema Definition ● It is recommended to to have the schema definition on the first level "$schema": "http://json-schema.org/draft-07/schema#" ● JSON Schema used versions: – Draft 4 – Draft 6 – Draft 7 – Draft 8
  • 19. Hands on JSON Validating with JSON Schema ● Check if the JSON instance respects the definitions { "persons": [ { "id": 2, "firstname": "Jane", "familyname": "Doe", "email": "jane@oxygenxml..com", "age": 37 } ] } Invalid email address Expected string, but fund integer Required key [lastname] not found [familyname] is not permitted
  • 20. Hands on JSON Associate JSON Schema ● Associating a Schema to JSON Documents – Directly in JSON document – using $schema property – In application options { "$schema": "person-schema.json", "persons" [ ... ] } Absolute or relative URI
  • 21. Hands on JSON Validating JSON Schema ● Check for well-formedness ● Validate accordingly to the Internet Engineering Task Force (IETF) Specification
  • 22. Hands on JSON Validating JSON with Schematron ● Specify the JSON structure using JSON Schema ● Express co-constraints and define custom rules using Schematron
  • 23. Hands on JSON Schematron for JSON ● Use XPath to express the rules <sch:rule context="persons"> <sch:assert test="number(age) > preceding-sibling::node()/age "> The person age must be grater than the previous person age </sch:assert> </sch:rule>
  • 24. Hands on JSON Schematron using JSONPath ● Schematron reimagined for JSON with no whiff of XML/XPath ● Moved out of the XPath and use JSONPath https://github.com/amer-ali/jsontron "rule": [ {"context": "$.persons.*", "assert": [ {"test": "(jp.query(contextNode,'$..age') >= 21", "message": "The person age must be grater than 21"} ] } ]
  • 25. Hands on JSON Querying and Transforming ● Query using JSON Pointer, JSONiq, or XPath ● Transform JSON using JavaScript, XSLT, XQuery
  • 26. Hands on JSON JSON Pointer Used to identify a specific value within a JSON document #/persons/0/email Matches first person email Specification https://tools.ietf.org/html/rfc6901
  • 27. Hands on JSON JSONiq A query and processing language for JSON www.jsoniq.org
  • 28. Hands on JSON XPath ● Powerful language for queering XML documents ● Was adopted by applications also for JSON /persons[2]/email Matches second person email
  • 29. Hands on JSON Process JSON with JavaScript ● Most popular way to process JSON documents ● Multiple libraries var json = '{"name":”John Doe”, "age":42}'; obj = JSON.parse(json); console.log(obj.name); // Result John Doe console.log(obj.age); // Result 42
  • 30. Hands on JSON Transform using XSLT/XQuery ● Transform JSON Documents to Different Formats ● Different functions to process JSON document: ● json-doc($href as xs:string?) as item()? ● json-to-xml($json-text as xs:string?) as document-node()?
  • 31. Hands on JSON Converting JSON Documents ● JSON to XML and XML to JSON ● Convert using XSLT ● Online Converters
  • 32. Hands on JSON JSON to XML { "personnel": { "person": [ { "id": 1, "name": { "family": "Worker", "given": "One" }, "email": "one@oxygenxml.com", "link": {"manager": "Big.Boss"} }, { "id": 2, "name": { "family": "Worker", "given": "Two" }, "email": "two@oxygenxml.com", "link": {"manager": "Big.Boss"} } ] } } <personnel> <person> <id>1</id> <name> <family>Worker</family> <given>One</given> </name> <email>one@oxygenxml.com</email> <link> <manager>Big.Boss</manager> </link> </person> <person> <id>2</id> <name> <family>Worker</family> <given>Two</given> </name> <email>two@oxygenxml.com</email> <link> <manager>Big.Boss</manager> </link> </person> </personnel>
  • 33. Hands on JSON JSON to XML Conversion Details ● A <JSON> element is added as root if the converted JSON has multiple properties on the first level ● An <array> element is added as root if the converted JSON is an array [ {"name": "Boss"}, {"name": "Worker"} ] <array> <array> <name>Boss</name> </array> <array> <name>Worker</name> </array> </array> { "person": "one", "id": "personnel-id" } <JSON> <person>one</person> <id>personnel-id</id> </JSON>
  • 34. Hands on JSON 1 XML to JSON <personnel> <person id="1"> <name> <family>Worker</family> <given>One</given> </name> <email>one@oxygenxml.com</email> <link manager="harris.anderson"/> </person> <person> <id>2</id> <name> <family>Worker</family> <given>Two</given> </name> <email>two@oxygenxml.com</email> <link manager="harris.anderson"/> </person> </personnel> { "personnel": { "person": [ { "id": 1, "name": { "family": "Worker", "given": "One" }, "email": "one@oxygenxml.com", "link": {"manager": "harris.anderson"} }, { "id": 2, "name": { "family": "Worker", "given": "Two" }, "email": "two@oxygenxml.com", "link": {"manager": "harris.anderson"} } ] } }
  • 35. Hands on JSON XML to JSON Conversion Details ● XML attributes are converted to properties <person id="1"/> {"person": {"id": 1}} ● Multiple elements with the same name are converted into an array <person/> <person/> "person": ["",""] ● Text in mixed content will be converted in a #text property <p>This is an <b>example</b>!</p> p": {"#text": "This is an","b": "example","#text1": "!"}
  • 36. Hands on JSON Convert using XSLT ● Library that converts XML to JSON using XSLT https://github.com/bramstein/xsltjson XSLT Specification for JSON http://www.w3.org/TR/xslt-30/#json
  • 37. Hands on JSON Online Converter ● Online XML to JSON Converters Convert between XML and JSON
  • 38. Hands on JSON Conclusion ● JSON conforms to ECMA/ISO specification ● Validate JSON with JSON Schema ● Query and process JSON using JSON Pointer, JSONiq, XPath, or JavaScript and XSLT ● Conversions to convert between JSON and XML
  • 39. Questions? Octavian Nadolu Software Architect at Syncro Soft octavian.nadolu@oxygenxml.com Twitter: @OctavianNadolu LinkedIn: octaviannadolu https://sundt01.honestly.de