Rdf Repository Replacing Relational Database

Total Page:16

File Type:pdf, Size:1020Kb

Rdf Repository Replacing Relational Database RDF REPOSITORY REPLACING RELATIONAL DATABASE 1B.Srinivasa Rao, 2Dr.G.Appa Rao 1,2Department of CSE, GITAM University Email:[email protected],[email protected] Abstract-- This study is to propose a flexible enable it. One such technology is RDF (Resource information storage mechanism based on the Description Framework)[2]. RDF is a directed, principles of Semantic Web that enables labelled graph for representing information in the information to be searched rather than queried. Web. This can be perceived as a repository In this study, a prototype is developed where without any predefined structure the focus is on the information rather than the The information stored in the traditional structure. Here information is stored in a RDBMS’s requires structure to be defined structure that is constructed on the fly. Entities upfront. On the contrary, information could be in the system are connected and form a graph, very complex to structure upfront despite the similar to the web of data in the Internet. This tremendous potential offered by the existing data is persisted in a peculiar way to optimize database systems. In the ever changing world, querying on this graph of data. All information another important characteristic of information relating to a subject is persisted closely so that in a system that impacts its structure is the reqeusting any information of a subject could be modification/enhancement to the system. This is handled in one call. Also, the information is a big concern with many software systems that maintained in triples so that the entire exist today and there is no tidy approach to deal relationship from subject to object via the with the problem. predicate is captured in one record. 1.1. Relational databases Relational databases need a structure to be Key Concepts: Entity, Subject, Predicate, defined upfront and this might not be feasible Object, RDF Triple always with the complexities in the real 1. Introduction world.Relational databases have immense The Semantic Web is a collaborative movement capabilities to offer, however they do pose some led by the international standards body, the serious concerns in some aspects and the most World Wide Web Consortium (W3C).[1] The important of them are semantic web is a “web of data” that enables Enhancement to structure machines to understand the semantics of o requires a great deal of effort to update information on the World Wide Web. The term the structure of information stored "Semantic Web" is often used more specifically o total understanding of the system and its to refer to the formats and technologies that dependencies ISSN (PRINT): 2393-8374, (ONLINE): 2394-0697,VOLUME-2, ISSUE-4,2015 27 INTERNATIONAL JOURNAL OF CURRENT ENGINEERING AND SCIENTIFIC RESEARCH (IJCESR) o complex analysis to ensure the system is not impacted even after the structural change o focussed monitoring once the change is put in place Scaling o scaling in line with the application is not always possible because of centralized nature Figure 2: Generalized RDF Model o when data set tends to grow, traditional The above picture represents an entity being an databases cannot handle it object and a subject in different contexts. 2. Background 2.2. Class Diagram 2.1. RDF Model Figure 1: RDF Model The RDF model has a triple consisting of subject, predicate and an object. The subject is Figure 3: Class diagram the entity that is being dealt with i.e. the subject and its characteristics are being discussed. The RDF data model is similar to classic Predicate indicates one characteristic type of the conceptual modelling approaches such as subject and the object represents the Entity-Relationship or Class diagrams,[10] as it characteristic. is based upon the idea of making statements about resources (in particular Web resources) in An analogy to understand this better is to the form of subject-predicate-object consider the {predicate, object} pair as an expressions. These expressions are known {attribute name, attribute value} pair for the as triples in RDF terminology. The subject subject. A subject can have multiple attributes, denotes the resource, and the predicate denotes and each of subject, attribute name and attribute traits or aspects of the resource and expresses a value is fully scoped. This ensures there is a relationship between the subject and the object. context associated with each triplet.Figure 1: RDF Model RDF is based on the idea of identifying things using Web identifiers (called Uniform Resource A subject can have any number of Identifiers, or URIs[4]), and describing characteristics and an object in one context resources in terms of simple properties and could be a subject in another context. Similarly, property values. This enables RDF to represent a predicate could also be a subject or an object simple statements about resources as a graph of in other contexts. nodes and arcs representing the resources, their properties and values. ISSN (PRINT): 2393-8374, (ONLINE): 2394-0697,VOLUME-2, ISSUE-4,2015 28 INTERNATIONAL JOURNAL OF CURRENT ENGINEERING AND SCIENTIFIC RESEARCH (IJCESR) syntax-ns#" xmlns:si="http://www.w3schools.com/rdf/"> <rdf:Description rdf:about="Thomas Edison"> <si:inventor>Electric bulb</si:inventor> <si:mbox>[email protected]</si:mbox> </rdf:Description> F <rdf:Description rdf:about="Albert igure 4: An RDF Graph Describing David Einstein"> <si:discoverer>Photoelectric Figure 4 illustrates that RDF uses URIs to Effect</si:discoverer> identify individuals, physical objects, properties and values of properties. <si:mbox>[email protected]</si:mbox> This concept is extended to define relations between objects in a relational database thereby </rdf:Description> eliminating the structure. The main advantage <rdf:Description rdf:about="Max Planck"> that this approach offers is the traversal from one object to another based on the relations <si:founder>Quantum Theory</si:founder> either directly or by hopping across objects. 2.3. Storage and querying <si:mbox>[email protected]</si:mbox> The RDF store can be a file system, RDBMS or </rdf:Description> any other store. <rdf:Description rdf:about="Max Planck"> Let us consider information of individuals and <si:age>43</si:age> their discoveries or pioneering works. Then we query the store for the mailbox and pioneering </rdf:Description> work where both of them exist. This is a simple <rdf:Description rdf:about="Marie Curie"> case that shows that information can be queried from an RDF store using query languages very similar to the ones used to query traditional <si:mbox>[email protected]</si:mbox> relational databases. </rdf:Description> The RDF format consists of triples namely <rdf:Description rdf:about="Marie Curie"> Subject, Object and Predicate. The Subject and Object are related to each other via a Predicate. <si:pioneer>Radioactivity</si:pioneer> This information can be maintained as simple </rdf:Description> XML as shown below </rdf:RDF> <?xml version="1.0"?> This information is maintained in an RDF store <rdf:RDF without knowledge of how it is structured or xmlns:rdf="http://www.w3.org/1999/02/22-rdf- maintained internally by RDF engines. This gives the flexibility to add new dimensions to ISSN (PRINT): 2393-8374, (ONLINE): 2394-0697,VOLUME-2, ISSUE-4,2015 29 INTERNATIONAL JOURNAL OF CURRENT ENGINEERING AND SCIENTIFIC RESEARCH (IJCESR) the existing information simply executing a database, MongoDB stores structured data query. On the contrary, when a relational as JSON-like documents with dynamic schemas database has to be updated with a new (MongoDB calls the format BSON), making the dimension, a lock has to be acquired and the integration of data in certain types of database is not usable until the dimension is applications easier and faster. added. MongoDB scales horizontally using sharding Traditional RDBMS’s are queried using SQL, [9]. The developer chooses a shard key, which similarly there are querying languages like determines how the data in a collection will be SPARQL[5]/SeRQL[6] to query information distributed. The data is split into ranges (based from an RDF store. SPARQL allows for a query on the shard key) and distributed across to consist of triple patterns, conjunctions, multiple shards. (A shard is a master with one disjunctions, and optional patterns. or more slaves.) In order to fetch the mailbox and pioneering 3. Architecture work where both exist, a SPARQL query would Our system architecture consists of three major look like components 1. RDF Data store SELECT ?mbox ?pioneer where {?x 2. Reactor <http://www.w3schools.com/rdf/mbox> ?mbox a. Data de-normalizer . ?x <http://www.w3schools.com/rdf/pioneer> b. View generator ?pioneer} 3. Query Interface This returns the response Any external system can populate data in RDF "Radioactivity" [email protected] Data store. For every such insert/update of data in the RDF Data store, a trigger begins a One of the core concepts of RDF is its open reaction. The reactor picks up the change and structure i.e. there is no need for a structure to data de-normalizer component de-normalizes be defined upfront. This property removes the the data by breaking it into simple relational complexity of updating the system. Information triples and further breaks up the data into in RDF could be distributed across multiple subject, object and predicate. The view systems like the information on the web. This generator picks up this information and distributed nature of persisting information generates materialized views. These views are allows the systems relying on RDF to scale then persisted in MongoDB store for optimal without the need to do a lot of manual retrieval. configuration. The query interface is a light weight converter This helps in overcoming the scaling problem. that lets clients query for information. It directly talks to MongoDB and converts the data back 2.4.
Recommended publications
  • Document Databases, JSON, Mongodb 17
    MI-PDB, MIE-PDB: Advanced Database Systems http://www.ksi.mff.cuni.cz/~svoboda/courses/2015-2-MIE-PDB/ Lecture 13: Document Databases, JSON, MongoDB 17. 5. 2016 Lecturer: Martin Svoboda [email protected] Authors: Irena Holubová, Martin Svoboda Faculty of Mathematics and Physics, Charles University in Prague Course NDBI040: Big Data Management and NoSQL Databases Document Databases Basic Characteristics Documents are the main concept Stored and retrieved XML, JSON, … Documents are Self-describing Hierarchical tree data structures Can consist of maps, collections, scalar values, nested documents, … Documents in a collection are expected to be similar Their schema can differ Document databases store documents in the value part of the key-value store Key-value stores where the value is examinable Document Databases Suitable Use Cases Event Logging Many different applications want to log events Type of data being captured keeps changing Events can be sharded by the name of the application or type of event Content Management Systems, Blogging Platforms Managing user comments, user registrations, profiles, web-facing documents, … Web Analytics or Real-Time Analytics Parts of the document can be updated New metrics can be easily added without schema changes E-Commerce Applications Flexible schema for products and orders Evolving data models without expensive data migration Document Databases When Not to Use Complex Transactions Spanning Different Operations Atomic cross-document operations Some document databases do support (e.g., RavenDB) Queries against Varying Aggregate Structure Design of aggregate is constantly changing → we need to save the aggregates at the lowest level of granularity i.e., to normalize the data Document Databases Representatives Lotus Notes Storage Facility JSON JavaScript Object Notation Introduction • JSON = JavaScript Object Notation .
    [Show full text]
  • Smart Grid Serialization Comparison
    Downloaded from orbit.dtu.dk on: Sep 28, 2021 Smart Grid Serialization Comparison Petersen, Bo Søborg; Bindner, Henrik W.; You, Shi; Poulsen, Bjarne Published in: Computing Conference 2017 Link to article, DOI: 10.1109/SAI.2017.8252264 Publication date: 2017 Document Version Peer reviewed version Link back to DTU Orbit Citation (APA): Petersen, B. S., Bindner, H. W., You, S., & Poulsen, B. (2017). Smart Grid Serialization Comparison. In Computing Conference 2017 (pp. 1339-1346). IEEE. https://doi.org/10.1109/SAI.2017.8252264 General rights Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of accessing publications that users recognise and abide by the legal requirements associated with these rights. Users may download and print one copy of any publication from the public portal for the purpose of private study or research. You may not further distribute the material or use it for any profit-making activity or commercial gain You may freely distribute the URL identifying the publication in the public portal If you believe that this document breaches copyright please contact us providing details, and we will remove access to the work immediately and investigate your claim. Computing Conference 2017 18-20 July 2017 | London, UK Smart Grid Serialization Comparision Comparision of serialization for distributed control in the context of the Internet of Things Bo Petersen, Henrik Bindner, Shi You Bjarne Poulsen DTU Electrical Engineering DTU Compute Technical University of Denmark Technical University of Denmark Lyngby, Denmark Lyngby, Denmark [email protected], [email protected], [email protected] [email protected] Abstract—Communication between DERs and System to ensure that the control messages are received within a given Operators is required to provide Demand Response and solve timeframe, depending on the needs of the power grid.
    [Show full text]
  • Semantics Developer's Guide
    MarkLogic Server Semantic Graph Developer’s Guide 2 MarkLogic 10 May, 2019 Last Revised: 10.0-8, October, 2021 Copyright © 2021 MarkLogic Corporation. All rights reserved. MarkLogic Server MarkLogic 10—May, 2019 Semantic Graph Developer’s Guide—Page 2 MarkLogic Server Table of Contents Table of Contents Semantic Graph Developer’s Guide 1.0 Introduction to Semantic Graphs in MarkLogic ..........................................11 1.1 Terminology ..........................................................................................................12 1.2 Linked Open Data .................................................................................................13 1.3 RDF Implementation in MarkLogic .....................................................................14 1.3.1 Using RDF in MarkLogic .........................................................................15 1.3.1.1 Storing RDF Triples in MarkLogic ...........................................17 1.3.1.2 Querying Triples .......................................................................18 1.3.2 RDF Data Model .......................................................................................20 1.3.3 Blank Node Identifiers ..............................................................................21 1.3.4 RDF Datatypes ..........................................................................................21 1.3.5 IRIs and Prefixes .......................................................................................22 1.3.5.1 IRIs ............................................................................................22
    [Show full text]
  • XSAMS: XML Schema for Atomic, Molecular and Solid Data
    XSAMS: XML Schema for Atomic, Molecular and Solid Data Version 0.1.1 Draft Document, January 14, 2011 This version: http://www-amdis.iaea.org/xsams/docu/v0.1.1.pdf Latest version: http://www-amdis.iaea.org/xsams/docu/ Previous versions: http://www-amdis.iaea.org/xsams/docu/v0.1.pdf Editors: M.L. Dubernet, D. Humbert, Yu. Ralchenko Authors: M.L. Dubernet, D. Humbert, Yu. Ralchenko, E. Roueff, D.R. Schultz, H.-K. Chung, B.J. Braams Contributors: N. Moreau, P. Loboda, S. Gagarin, R.E.H. Clark, M. Doronin, T. Marquart Abstract This document presents a proposal for an XML schema aimed at describing Atomic, Molec- ular and Particle Surface Interaction Data in distributed databases around the world. This general XML schema is a collaborative project between International Atomic Energy Agency (Austria), National Institute of Standards and Technology (USA), Universit´ePierre et Marie Curie (France), Oak Ridge National Laboratory (USA) and Paris Observatory (France). Status of this document It is a draft document and it may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use this document as reference materials or to cite them as other than “work in progress”. Acknowledgements The authors wish to acknowledge all colleagues and institutes, atomic and molecular database experts and physicists who have collaborated through different discussions to the building up of the concepts described in this document. Change Log Version 0.1: June 2009 Version 0.1.1: November 2010 Contents 1 Introduction 11 1.1 Motivation..................................... 11 1.2 Limitations..................................... 12 2 XSAMS structure, types and attributes 13 2.1 Atomic, Molecular and Particle Surface Interaction Data XML Schema Structure 13 2.2 Attributes ....................................
    [Show full text]
  • Rdfa in XHTML: Syntax and Processing Rdfa in XHTML: Syntax and Processing
    RDFa in XHTML: Syntax and Processing RDFa in XHTML: Syntax and Processing RDFa in XHTML: Syntax and Processing A collection of attributes and processing rules for extending XHTML to support RDF W3C Recommendation 14 October 2008 This version: http://www.w3.org/TR/2008/REC-rdfa-syntax-20081014 Latest version: http://www.w3.org/TR/rdfa-syntax Previous version: http://www.w3.org/TR/2008/PR-rdfa-syntax-20080904 Diff from previous version: rdfa-syntax-diff.html Editors: Ben Adida, Creative Commons [email protected] Mark Birbeck, webBackplane [email protected] Shane McCarron, Applied Testing and Technology, Inc. [email protected] Steven Pemberton, CWI Please refer to the errata for this document, which may include some normative corrections. This document is also available in these non-normative formats: PostScript version, PDF version, ZIP archive, and Gzip’d TAR archive. The English version of this specification is the only normative version. Non-normative translations may also be available. Copyright © 2007-2008 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply. Abstract The current Web is primarily made up of an enormous number of documents that have been created using HTML. These documents contain significant amounts of structured data, which is largely unavailable to tools and applications. When publishers can express this data more completely, and when tools can read it, a new world of user functionality becomes available, letting users transfer structured data between applications and web sites, and allowing browsing applications to improve the user experience: an event on a web page can be directly imported - 1 - How to Read this Document RDFa in XHTML: Syntax and Processing into a user’s desktop calendar; a license on a document can be detected so that users can be informed of their rights automatically; a photo’s creator, camera setting information, resolution, location and topic can be published as easily as the original photo itself, enabling structured search and sharing.
    [Show full text]
  • Spindle Documentation Release 2.0.0
    spindle Documentation Release 2.0.0 Jorge Ortiz, Jason Liszka June 08, 2016 Contents 1 Thrift 3 1.1 Data model................................................3 1.2 Interface definition language (IDL)...................................4 1.3 Serialization formats...........................................4 2 Records 5 2.1 Creating a record.............................................5 2.2 Reading/writing records.........................................6 2.3 Record interface methods........................................6 2.4 Other methods..............................................7 2.5 Mutable trait...............................................7 2.6 Raw class.................................................7 2.7 Priming..................................................7 2.8 Proxies..................................................8 2.9 Reflection.................................................8 2.10 Field descriptors.............................................8 3 Custom types 9 3.1 Enhanced types..............................................9 3.2 Bitfields..................................................9 3.3 Type-safe IDs............................................... 10 4 Enums 13 4.1 Enum value methods........................................... 13 4.2 Companion object methods....................................... 13 4.3 Matching and unknown values...................................... 14 4.4 Serializing to string............................................ 14 4.5 Examples................................................. 14 5 Working
    [Show full text]
  • CBOR (RFC 7049) Concise Binary Object Representation
    CBOR (RFC 7049) Concise Binary Object Representation Carsten Bormann, 2015-11-01 1 CBOR: Agenda • What is it, and when might I want it? • How does it work? • How do I work with it? 2 CBOR: Agenda • What is it, and when might I want it? • How does it work? • How do I work with it? 3 Slide stolen from Douglas Crockford History of Data Formats • Ad Hoc • Database Model • Document Model • Programming Language Model Box notation TLV 5 XML XSD 6 Slide stolen from Douglas Crockford JSON • JavaScript Object Notation • Minimal • Textual • Subset of JavaScript Values • Strings • Numbers • Booleans • Objects • Arrays • null Array ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] [ [0, -1, 0], [1, 0, 0], [0, 0, 1] ] Object { "name": "Jack B. Nimble", "at large": true, "grade": "A", "format": { "type": "rect", "width": 1920, "height": 1080, "interlace": false, "framerate": 24 } } Object Map { "name": "Jack B. Nimble", "at large": true, "grade": "A", "format": { "type": "rect", "width": 1920, "height": 1080, "interlace": false, "framerate": 24 } } JSON limitations • No binary data (byte strings) • Numbers are in decimal, some parsing required • Format requires copying: • Escaping for strings • Base64 for binary • No extensibility (e.g., date format?) • Interoperability issues • I-JSON further reduces functionality (RFC 7493) 12 BSON and friends • Lots of “binary JSON” proposals • Often optimized for data at rest, not protocol use (BSON ➔ MongoDB) • Most are more complex than JSON 13 Why a new binary object format? • Different design goals from current formats – stated up front in the document • Extremely small code size – for work on constrained node networks • Reasonably compact data size – but no compression or even bit-fiddling • Useful to any protocol or application that likes the design goals 14 Concise Binary Object Representation (CBOR) 15 “Sea Boar” “Sea Boar” 16 Design goals (1 of 2) 1.
    [Show full text]
  • JSON JSON (Javascript Object Notation) Ecmascript Javascript
    ECMAScript JSON ECMAScript is standardized JavaScript. The current version is the 12th edition: Péter Jeszenszky Ecma International, ECMAScript 2021 Language Specification, Standard ECMA-262, 12th ed., June 2021. https://www.ecma- international.org/publications-and-standards/standards/ecma-262/ October 8, 2021 The next version currently under development is ECMAScript 2022: ECMAScript 2022 Language Specification https://tc39.es/ecma262/ Péter Jeszenszky JSON October 8, 2021 1 / 94 Péter Jeszenszky JSON October 8, 2021 3 / 94 JSON (JavaScript Object Notation) JavaScript Lightweight, textual, and platform independent data exchange format. Used for representing structured data. The term JavaScript is used for the implementations of ECMAScript by different vendors. Can be read and written easily by humans. See also: JavaScript technologies overview Can be generated and processed easily by computer programs. https://developer.mozilla.org/en- US/docs/Web/JavaScript/JavaScript_technologies_overview Originates from the ECMAScript programming language. Website: https://www.json.org/ Péter Jeszenszky JSON October 8, 2021 2 / 94 Péter Jeszenszky JSON October 8, 2021 4 / 94 JavaScript Engines (1) Node.js (1) SpiderMonkey (written in: C/C++; license: Mozilla Public License 2.0) https://spidermonkey.dev/ A JavaScript runtime environment built on the V8 JavaScript engine The JavaScript engine of the Mozilla Project. that is designed to build scalable network applications. V8 (written in: C++; license: New BSD License) https://v8.dev/ Website: https://nodejs.org/ https://github.com/nodejs/node https://github.com/v8/v8/ License: MIT License The JavaScript engine of Chromium. Written in: C++, JavaScript JavaScriptCore (written in: C++; license: LGPLv2) https://developer.apple.com/documentation/javascriptcore https: Platform: Linux, macOS, Windows //github.com/WebKit/webkit/tree/master/Source/JavaScriptCore The JavaScript engine developed for the WebKit rendering engine.
    [Show full text]
  • Robust Web Content Extraction Marek Kowalkiewicz Maria E
    Robust Web Content Extraction Marek Kowalkiewicz Maria E. Orlowska Tomasz Kaczmarek Witold Abramowicz Department of Management Department of Information Department of Management Department of Management Information Systems Technology and Electrical Information Systems Information Systems The Poznan University of Engineering The Poznan University of The Poznan University of Economics The University of Economics Economics Al. Niepodleglosci 10 Queensland Al. Niepodleglosci 10 Al. Niepodleglosci 10 60-967 Poznan, Poland Brisbane, St. Lucia 60-967 Poznan, Poland 60-967 Poznan, Poland +48 (61) 8543631 QLD 4072, Australia +48 (61) 8543631 +48 (61) 8543381 +61 (7) 33652989 [email protected] [email protected] [email protected] [email protected] ABSTRACT There is a number of technologies to extract information from We present an empirical evaluation and comparison of two webpages. For a state of the art analysis, see previously content extraction methods in HTML: absolute XPath expressions mentioned paper [2] and an extensive study by Laender et al. [3]. and relative XPath expressions. We argue that the relative XPath Robustness of content extraction methods, with a focus on XPath, expressions, although not widely used, should be used in has been presented in a work by Abe and Hori [1]. The authors preference to absolute XPath expressions in extracting content proposed four content anchoring approaches and tested them on from human-created Web documents. Evaluation of robustness documents from four Web sites. The samples used in theory study covers four thousand queries executed on several hundred were too small to be statistically valid. However the authors make webpages. We show that in referencing parts of real world a significant step towards establishing an understanding of the dynamic HTML documents, relative XPath expressions are on applicability of content extraction methods in real world Web average significantly more robust than absolute XPath ones.
    [Show full text]
  • Stupeflask Documentation
    Stupeflask Documentation Numberly Jan 20, 2020 Contents 1 Install 3 2 Comparison 5 3 Tests 7 4 License 9 5 Documentation 11 5.1 Better application defaults........................................ 11 5.2 Easier collection of configuration values................................. 13 5.3 Native ObjectId support......................................... 13 5.4 API Reference.............................................. 14 5.5 Cursor support.............................................. 18 6 Indices and tables 19 Python Module Index 21 Index 23 i ii Stupeflask Documentation a.k.a. « Flask on steroids » An opinionated Flask extension designed by and for web developers to reduce boilerplate code when working with Marshmallow, MongoDB and/or JSON. Documentation: https://flask-stupe.readthedocs.io • Return any object type in views, and it will be coerced to a flask.Response • Validate payloads through Marshmallow schemas • Easily add JSON converters for any custom type • Fetch all the blueprints from a whole module in one line • Native ObjectId support for both Flask and Marshmallow • Powerful configuration management • Decorators to handle authentication, permissions, and pagination • 100% coverage and no dependency Contents 1 Stupeflask Documentation 2 Contents CHAPTER 1 Install $ pip install flask-stupe 3 Stupeflask Documentation 4 Chapter 1. Install CHAPTER 2 Comparison Here is a comparison of a bare Flask application and its equivalent Stupeflask version. They both rely on MongoDB, handle input and output in JSON, and allow to create a user and retrieve
    [Show full text]
  • Advanced JSON Handling in Go 19:40 05 Mar 2020 Jonathan Hall Devops Evangelist / Go Developer / Clean Coder / Salsa Dancer About Me
    Advanced JSON handling in Go 19:40 05 Mar 2020 Jonathan Hall DevOps Evangelist / Go Developer / Clean Coder / Salsa Dancer About me Open Source contributor; CouchDB PMC, author of Kivik Core Tech Lead for Lana Former eCommerce Dev Manager at Bugaboo Former backend developer at Teamwork.com Former backend developer at Booking.com Former tech lead at eFolder/DoubleCheck 2 Show of hands Who has... ...used JSON in a Go program? ...been frustrated by Go's strict typing when dealing with JSON? ...felt limited by Go's standard JSON handling? What have been your biggest frustrations? 3 Today's Topics Very brief intro to JSON in Go Basic use of maps and structs Handling inputs of unknown type Handling data with some unknown fields 4 A brief intro to JSON JavaScript Object Notation, defined by RFC 8259 Human-readable, textual representation of arbitrary data Limted types: null, Number, String, Boolean, Array, Object Broad applications: Config files, data interchange, simple messaging 5 Alternatives to JSON YAML, TOML, INI BSON, MessagePack, CBOR, Smile XML ProtoBuf Custom/proprietary formats Many principles discussed in this presentation apply to any of the above formats. 6 Marshaling JSON Creating JSON from a Go object is (usually) very straight forward: func main() { x := map[string]string{ "foo": "bar", } data, _ := json.Marshal(x) fmt.Println(string(data)) } Run 7 Marshaling JSON, #2 Creating JSON from a Go object is (usually) very straight forward: func main() { type person struct { Name string `json:"name"` Age int `json:"age"` Description string `json:"descr,omitempty"` secret string // Unexported fields are never (un)marshaled } x := person{ Name: "Bob", Age: 32, secret: "Shhh!", } data, _ := json.Marshal(x) fmt.Println(string(data)) } Run 8 Unmarshaling JSON Unmarshaling JSON is often a bit trickier.
    [Show full text]
  • JSON As an XML Alternative
    JSON The Fat-Free Alternative to XML { “Lecture”: 27, “Course”: “CSC375”, “Days”: ”TTh", “Instructor”: “Haidar Harmanani” } JSON as an XML Alternative • JSON is a light-weight alternative to XML for data- interchange • JSON = JavaScript Object Notation – It’s really language independent – most programming languages can easily read it and instantiate objects or some other data structure • Defined in RFC 4627 • Started gaining tracking ~2006 and now widely used • http://json.org/ has more information JSON as an XML Alternative • What is JSON? – JSON is language independent – JSON is "self-describing" and easy to understand – *JSON uses JavaScript syntax for describing data objects, but JSON is still language and platform independent. JSON parsers and JSON libraries exists for many different programming languages. • JSON -Evaluates to JavaScript Objects – The JSON text format is syntactically identical to the code for creating JavaScript objects. – Because of this similarity, instead of using a parser, a JavaScript program can use the built-in eval() function and execute JSON data to produce native JavaScript objects. Example {"firstName": "John", l This is a JSON object "lastName" : "Smith", "age" : 25, with five key-value pairs "address" : l Objects are wrapped by {"streetAdr” : "21 2nd Street", curly braces "city" : "New York", "state" : "NY", l There are no object IDs ”zip" : "10021"}, l Keys are strings "phoneNumber": l Values are numbers, [{"type" : "home", "number": "212 555-1234"}, strings, objects or {"type" : "fax", arrays "number” : "646 555-4567"}] l Aarrays are wrapped by } square brackets The BNF is simple When to use JSON? • SOAP is a protocol specification for exchanging structured information in the implementation of Web Services.
    [Show full text]