SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
Perl5 VS JSON
The Perl Conference 2019 in Pittsburgh - Lightning Talks
Kenta SATO (a.k.a. @karupanerura)
Kenta SATO a.k.a. @karupanerura
• PAUSE ID: KARUPA
• TOML::Parser, Time::Strptime, DBD::BlackHole, etc..
• Japan Perl Association - 3rd Representative Director
• Shibuya.pm - Leader
• DeNA, Co,. LTD. - Software Engineer
tl;dr
• JSON is de facto standard serialization format for IPC in today
• JSON data type is important for almost other languages
• Typed data schema is great solution for JSON encoding
• JSON::Types is match for simple cases
• Cpanel::JSON::XS::Type is match for almost cases
Background
Modern Web Application Development
• JavaScript side DOM rendering
• e.g.) React.js, Vue.js, etc..
• Minimam HTML rendering on Server-side application
• Almost data is provided by JSON Web API.
JSON is used for many many cases
• Authentication/Authorization
• JWT(JWS), OIDC, etc..
• Mobile (Android/iOS) applications
• (Internal/External) Web APIs
• microservices, customer’s application, etc..
JSON is a de facto standard
serialization format for IPC today
Perl5 can encode/decode JSON!
JSON::(PP|XS)
Cpanel::JSON::(PP|XS)
No problem!
Really?
JSON encoding
JSON value has a type
Perl5 value can be 3 container types:
Scalar(SV), Array(AV), Hash(HV)
JSON value can be 6 data types:
null, boolean, number,
string, array, object
How to translate to JSON's data type
from Perl's container type?
Perl5 to JSON
• Hash -> object
• Array -> array
• Scalar(undef) -> null
• Scalar(special boolean blessed object) -> boolean
• Scalar -> number OR string
Perl5 to JSON
• Hash -> object
• Array -> array
• Scalar(undef) -> null
• Scalar(special boolean blessed object) -> boolean
• Scalar -> number OR string What’s going on?
Scalar to JSON (string|number)
• Looking internal SV flags
• Basic examples:
• PV(Literal: ‘a’) -> “a” (string)
• IV(Literal: 1) -> 1 (number)
• PVIV(Literal: ‘1’) -> “1” (string)
Looks like good for almost cases!
Really…?
Problem: SV flags is changed implicitly
• Too easy to change SV flags implicitly
# Example
my $x = 1; # IV (JSON encoding as number)
print "DEBUG: x = $xn"; # <-- Creates PV slot implicitly!
$x; # PVIV (JSON encoding as string)
Problem: JSON typing is important
// Java Script Example
const response = JSON.parse(`{"expiresTime":"3600"}`);
const expiresTime = response.expiresTime;
const nowEpoch = Math.floor(Date.now() / 1000);
const expiresAt = expiresTime + nowEpoch; // concat
console.log(expiresAt); // 3600XXXXXXXX
Strictly typing is serious problem for almost other languages.
Almost static typing languages throw error if type mismatch.
Almost dynamic typing languages change some behaviours
by the data type.
It’s too messy…
Solutions
JSON::Types
• Type annotation likes SV converter for JSON::(PP|XS)
use JSON::XS qw/encode_json/;
use JSON::Types;
my $json = encode_json([bool 0, number 1, string 2]);
say $json; # => [false,1,"2"]
Good: JSON::Types
• Very very simple implementation
• Easy to use it :)
Bad: JSON::Types
• SHOULD use it ONLY just before encoding
• Because, the converted SVs can be re-changed
• By after processes
• No converter from JSON Schema / OpenAPI (Swagger) / etc
Cpanel::JSON::XS::Type
• Typed data structure schema for Cpanel::JSON::XS
use Cpanel::JSON::XS;
use Cpanel::JSON::XS::Type;
my $schema =
[JSON_TYPE_BOOL, JSON_TYPE_INT, JSON_TYPE_STRING];
my $json = encode_json([0, 1, 2], $schema);
say $json; # => [false,1,"2"]
Good: Cpanel::JSON::XS::Type
• Never implicitly change the JSON data type
• Don’t look SV flags
• Explicitly type control
Bad: Cpanel::JSON::XS::Type
• No converter from JSON Schema / OpenAPI (Swagger) / etc
• Or exists...? (Maybe I don't know yet?)
Conclution
Conclution
• JSON is de facto standard serialization format for IPC today
• JSON data type is important for almost other languages
• Typed data schema is great solution for JSON encoding
• JSON::Types is match for simple cases
• Cpanel::JSON::XS::Type is match for almost cases
Thank you
Executable example codes in the slide
https://gist.github.com/karupanerura/223b2d862f0c0c966e706e7062cb8cc9

Contenu connexe

Tendances

An Evening Of DSLs: Microsoft Oslo
An Evening Of DSLs: Microsoft OsloAn Evening Of DSLs: Microsoft Oslo
An Evening Of DSLs: Microsoft OsloJames Lynch
 
Medepia ABAP JSON Library ZCL_MDP_JSON
Medepia ABAP JSON Library ZCL_MDP_JSONMedepia ABAP JSON Library ZCL_MDP_JSON
Medepia ABAP JSON Library ZCL_MDP_JSONFatih Pense
 
Bridging Ousterhout's Dichotomy
Bridging Ousterhout's DichotomyBridging Ousterhout's Dichotomy
Bridging Ousterhout's Dichotomyguest2838a0
 
Groovy best pratices at EWAY
Groovy best pratices at EWAYGroovy best pratices at EWAY
Groovy best pratices at EWAYĐào Hiệp
 
Netflix Global Search - Lucene Revolution
Netflix Global Search - Lucene RevolutionNetflix Global Search - Lucene Revolution
Netflix Global Search - Lucene Revolutionivan provalov
 
Language portfolio
Language portfolioLanguage portfolio
Language portfolioDhaval Dalal
 
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"Olga Lavrentieva
 
NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]Huy Do
 
Ruby formatters
Ruby formattersRuby formatters
Ruby formattersVisuality
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to RubyMark Menard
 
Join the dart side of webdevelopment reloaded
Join the dart side of webdevelopment reloadedJoin the dart side of webdevelopment reloaded
Join the dart side of webdevelopment reloadedClaudio d'Angelis
 
Introduction to protocol buffer
Introduction to protocol bufferIntroduction to protocol buffer
Introduction to protocol bufferTim (文昌)
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Gozhubert
 

Tendances (13)

An Evening Of DSLs: Microsoft Oslo
An Evening Of DSLs: Microsoft OsloAn Evening Of DSLs: Microsoft Oslo
An Evening Of DSLs: Microsoft Oslo
 
Medepia ABAP JSON Library ZCL_MDP_JSON
Medepia ABAP JSON Library ZCL_MDP_JSONMedepia ABAP JSON Library ZCL_MDP_JSON
Medepia ABAP JSON Library ZCL_MDP_JSON
 
Bridging Ousterhout's Dichotomy
Bridging Ousterhout's DichotomyBridging Ousterhout's Dichotomy
Bridging Ousterhout's Dichotomy
 
Groovy best pratices at EWAY
Groovy best pratices at EWAYGroovy best pratices at EWAY
Groovy best pratices at EWAY
 
Netflix Global Search - Lucene Revolution
Netflix Global Search - Lucene RevolutionNetflix Global Search - Lucene Revolution
Netflix Global Search - Lucene Revolution
 
Language portfolio
Language portfolioLanguage portfolio
Language portfolio
 
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
 
NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]
 
Ruby formatters
Ruby formattersRuby formatters
Ruby formatters
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Join the dart side of webdevelopment reloaded
Join the dart side of webdevelopment reloadedJoin the dart side of webdevelopment reloaded
Join the dart side of webdevelopment reloaded
 
Introduction to protocol buffer
Introduction to protocol bufferIntroduction to protocol buffer
Introduction to protocol buffer
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
 

Similaire à Perl5 VS JSON

Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Ramamohan Chokkam
 
Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Vitaly Baum
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesEelco Visser
 
Screaming fast json parsing on Android
Screaming fast json parsing on AndroidScreaming fast json parsing on Android
Screaming fast json parsing on AndroidKarthik Ramgopal
 
Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?mikaelbarbero
 
The Good, the Bad, and the Ugly: What Happened to Unicode and PHP 6
The Good, the Bad, and the Ugly: What Happened to Unicode and PHP 6The Good, the Bad, and the Ugly: What Happened to Unicode and PHP 6
The Good, the Bad, and the Ugly: What Happened to Unicode and PHP 6Andrei Zmievski
 
JS Fest 2019. Ryan Dahl. Deno, a new way to JavaScript
JS Fest 2019. Ryan Dahl. Deno, a new way to JavaScriptJS Fest 2019. Ryan Dahl. Deno, a new way to JavaScript
JS Fest 2019. Ryan Dahl. Deno, a new way to JavaScriptJSFestUA
 
Programming languages vienna
Programming languages viennaProgramming languages vienna
Programming languages viennagreg_s
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Languagezefhemel
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponLaurent Duveau
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Jimmy Schementi
 
Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009spierre
 
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)jaxLondonConference
 
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased ComparisonThrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased ComparisonIgor Anishchenko
 
Cassandra: Not Just NoSQL, It's MoSQL
Cassandra: Not Just NoSQL, It's MoSQLCassandra: Not Just NoSQL, It's MoSQL
Cassandra: Not Just NoSQL, It's MoSQLEric Evans
 
Erlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldErlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldZvi Avraham
 

Similaire à Perl5 VS JSON (20)

Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02
 
Avro
AvroAvro
Avro
 
Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
 
Screaming fast json parsing on Android
Screaming fast json parsing on AndroidScreaming fast json parsing on Android
Screaming fast json parsing on Android
 
Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?
 
The Good, the Bad, and the Ugly: What Happened to Unicode and PHP 6
The Good, the Bad, and the Ugly: What Happened to Unicode and PHP 6The Good, the Bad, and the Ugly: What Happened to Unicode and PHP 6
The Good, the Bad, and the Ugly: What Happened to Unicode and PHP 6
 
JS Fest 2019. Ryan Dahl. Deno, a new way to JavaScript
JS Fest 2019. Ryan Dahl. Deno, a new way to JavaScriptJS Fest 2019. Ryan Dahl. Deno, a new way to JavaScript
JS Fest 2019. Ryan Dahl. Deno, a new way to JavaScript
 
Programming languages vienna
Programming languages viennaProgramming languages vienna
Programming languages vienna
 
DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScript
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Language
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret Weapon
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011
 
Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009
 
Jaoo irony
Jaoo ironyJaoo irony
Jaoo irony
 
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)
 
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased ComparisonThrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased Comparison
 
Cassandra: Not Just NoSQL, It's MoSQL
Cassandra: Not Just NoSQL, It's MoSQLCassandra: Not Just NoSQL, It's MoSQL
Cassandra: Not Just NoSQL, It's MoSQL
 
Erlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldErlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent World
 
Bottom-Line Web Services
Bottom-Line Web ServicesBottom-Line Web Services
Bottom-Line Web Services
 

Plus de karupanerura

コンテキストと仲良く
コンテキストと仲良くコンテキストと仲良く
コンテキストと仲良くkarupanerura
 
The plan of Aniki 2.0
The plan of Aniki 2.0The plan of Aniki 2.0
The plan of Aniki 2.0karupanerura
 
The Crystal language *recently* update
The Crystal language *recently* updateThe Crystal language *recently* update
The Crystal language *recently* updatekarupanerura
 
TIme::Moment+Time::Strptime=
TIme::Moment+Time::Strptime=TIme::Moment+Time::Strptime=
TIme::Moment+Time::Strptime=karupanerura
 
Optimize perl5 code for perfomance freaks
Optimize perl5 code for perfomance freaksOptimize perl5 code for perfomance freaks
Optimize perl5 code for perfomance freakskarupanerura
 
Technology for reduce of mistakes - うっかりをなくす技術
Technology for reduce of mistakes - うっかりをなくす技術Technology for reduce of mistakes - うっかりをなくす技術
Technology for reduce of mistakes - うっかりをなくす技術karupanerura
 
Why we use mruby with Perl5?
Why we use mruby with Perl5?Why we use mruby with Perl5?
Why we use mruby with Perl5?karupanerura
 
Perlにおけるclass実装パターン
Perlにおけるclass実装パターンPerlにおけるclass実装パターン
Perlにおけるclass実装パターンkarupanerura
 
モジュール開発におけるぼくの試行錯誤
モジュール開発におけるぼくの試行錯誤モジュール開発におけるぼくの試行錯誤
モジュール開発におけるぼくの試行錯誤karupanerura
 
Aniki - The ORM as our great brother.
Aniki - The ORM as our great brother.Aniki - The ORM as our great brother.
Aniki - The ORM as our great brother.karupanerura
 
Perl5 meta programming
Perl5 meta programmingPerl5 meta programming
Perl5 meta programmingkarupanerura
 
mysqlcasual6-next-key-lock
mysqlcasual6-next-key-lockmysqlcasual6-next-key-lock
mysqlcasual6-next-key-lockkarupanerura
 

Plus de karupanerura (20)

コンテキストと仲良く
コンテキストと仲良くコンテキストと仲良く
コンテキストと仲良く
 
The plan of Aniki 2.0
The plan of Aniki 2.0The plan of Aniki 2.0
The plan of Aniki 2.0
 
Aniki::Internal
Aniki::InternalAniki::Internal
Aniki::Internal
 
The Crystal language *recently* update
The Crystal language *recently* updateThe Crystal language *recently* update
The Crystal language *recently* update
 
KOWAZA for mackerel
KOWAZA for mackerelKOWAZA for mackerel
KOWAZA for mackerel
 
TIme::Moment+Time::Strptime=
TIme::Moment+Time::Strptime=TIme::Moment+Time::Strptime=
TIme::Moment+Time::Strptime=
 
DateTimeX::Moment
DateTimeX::MomentDateTimeX::Moment
DateTimeX::Moment
 
Aniki has come
Aniki has comeAniki has come
Aniki has come
 
Optimize perl5 code for perfomance freaks
Optimize perl5 code for perfomance freaksOptimize perl5 code for perfomance freaks
Optimize perl5 code for perfomance freaks
 
Technology for reduce of mistakes - うっかりをなくす技術
Technology for reduce of mistakes - うっかりをなくす技術Technology for reduce of mistakes - うっかりをなくす技術
Technology for reduce of mistakes - うっかりをなくす技術
 
router-simple.cr
router-simple.crrouter-simple.cr
router-simple.cr
 
Why we use mruby with Perl5?
Why we use mruby with Perl5?Why we use mruby with Perl5?
Why we use mruby with Perl5?
 
はかたの塩
はかたの塩はかたの塩
はかたの塩
 
Gotanda.pmの紹介
Gotanda.pmの紹介Gotanda.pmの紹介
Gotanda.pmの紹介
 
すいすいSwift
すいすいSwiftすいすいSwift
すいすいSwift
 
Perlにおけるclass実装パターン
Perlにおけるclass実装パターンPerlにおけるclass実装パターン
Perlにおけるclass実装パターン
 
モジュール開発におけるぼくの試行錯誤
モジュール開発におけるぼくの試行錯誤モジュール開発におけるぼくの試行錯誤
モジュール開発におけるぼくの試行錯誤
 
Aniki - The ORM as our great brother.
Aniki - The ORM as our great brother.Aniki - The ORM as our great brother.
Aniki - The ORM as our great brother.
 
Perl5 meta programming
Perl5 meta programmingPerl5 meta programming
Perl5 meta programming
 
mysqlcasual6-next-key-lock
mysqlcasual6-next-key-lockmysqlcasual6-next-key-lock
mysqlcasual6-next-key-lock
 

Dernier

A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEselvakumar948
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 

Dernier (20)

A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 

Perl5 VS JSON

  • 1. Perl5 VS JSON The Perl Conference 2019 in Pittsburgh - Lightning Talks Kenta SATO (a.k.a. @karupanerura)
  • 2. Kenta SATO a.k.a. @karupanerura • PAUSE ID: KARUPA • TOML::Parser, Time::Strptime, DBD::BlackHole, etc.. • Japan Perl Association - 3rd Representative Director • Shibuya.pm - Leader • DeNA, Co,. LTD. - Software Engineer
  • 3. tl;dr • JSON is de facto standard serialization format for IPC in today • JSON data type is important for almost other languages • Typed data schema is great solution for JSON encoding • JSON::Types is match for simple cases • Cpanel::JSON::XS::Type is match for almost cases
  • 5. Modern Web Application Development • JavaScript side DOM rendering • e.g.) React.js, Vue.js, etc.. • Minimam HTML rendering on Server-side application • Almost data is provided by JSON Web API.
  • 6. JSON is used for many many cases • Authentication/Authorization • JWT(JWS), OIDC, etc.. • Mobile (Android/iOS) applications • (Internal/External) Web APIs • microservices, customer’s application, etc..
  • 7. JSON is a de facto standard serialization format for IPC today
  • 8. Perl5 can encode/decode JSON! JSON::(PP|XS) Cpanel::JSON::(PP|XS)
  • 12. JSON value has a type
  • 13. Perl5 value can be 3 container types: Scalar(SV), Array(AV), Hash(HV)
  • 14. JSON value can be 6 data types: null, boolean, number, string, array, object
  • 15. How to translate to JSON's data type from Perl's container type?
  • 16. Perl5 to JSON • Hash -> object • Array -> array • Scalar(undef) -> null • Scalar(special boolean blessed object) -> boolean • Scalar -> number OR string
  • 17. Perl5 to JSON • Hash -> object • Array -> array • Scalar(undef) -> null • Scalar(special boolean blessed object) -> boolean • Scalar -> number OR string What’s going on?
  • 18. Scalar to JSON (string|number) • Looking internal SV flags • Basic examples: • PV(Literal: ‘a’) -> “a” (string) • IV(Literal: 1) -> 1 (number) • PVIV(Literal: ‘1’) -> “1” (string)
  • 19. Looks like good for almost cases!
  • 21. Problem: SV flags is changed implicitly • Too easy to change SV flags implicitly # Example my $x = 1; # IV (JSON encoding as number) print "DEBUG: x = $xn"; # <-- Creates PV slot implicitly! $x; # PVIV (JSON encoding as string)
  • 22. Problem: JSON typing is important // Java Script Example const response = JSON.parse(`{"expiresTime":"3600"}`); const expiresTime = response.expiresTime; const nowEpoch = Math.floor(Date.now() / 1000); const expiresAt = expiresTime + nowEpoch; // concat console.log(expiresAt); // 3600XXXXXXXX Strictly typing is serious problem for almost other languages. Almost static typing languages throw error if type mismatch. Almost dynamic typing languages change some behaviours by the data type.
  • 25. JSON::Types • Type annotation likes SV converter for JSON::(PP|XS) use JSON::XS qw/encode_json/; use JSON::Types; my $json = encode_json([bool 0, number 1, string 2]); say $json; # => [false,1,"2"]
  • 26. Good: JSON::Types • Very very simple implementation • Easy to use it :)
  • 27. Bad: JSON::Types • SHOULD use it ONLY just before encoding • Because, the converted SVs can be re-changed • By after processes • No converter from JSON Schema / OpenAPI (Swagger) / etc
  • 28. Cpanel::JSON::XS::Type • Typed data structure schema for Cpanel::JSON::XS use Cpanel::JSON::XS; use Cpanel::JSON::XS::Type; my $schema = [JSON_TYPE_BOOL, JSON_TYPE_INT, JSON_TYPE_STRING]; my $json = encode_json([0, 1, 2], $schema); say $json; # => [false,1,"2"]
  • 29. Good: Cpanel::JSON::XS::Type • Never implicitly change the JSON data type • Don’t look SV flags • Explicitly type control
  • 30. Bad: Cpanel::JSON::XS::Type • No converter from JSON Schema / OpenAPI (Swagger) / etc • Or exists...? (Maybe I don't know yet?)
  • 32. Conclution • JSON is de facto standard serialization format for IPC today • JSON data type is important for almost other languages • Typed data schema is great solution for JSON encoding • JSON::Types is match for simple cases • Cpanel::JSON::XS::Type is match for almost cases
  • 33. Thank you Executable example codes in the slide https://gist.github.com/karupanerura/223b2d862f0c0c966e706e7062cb8cc9