Python Classroom Series – 01/Oct/2020

Story of Taj Group (Fictional)

  • Taj group has two applications from different vendors Preview
  • How can two applications exchange data?
    • We might need a data exchange format which
      • is easier to understand
      • No particular programming languages assumptions
      • Easy to read (by both humans & programs)
  • Lets Start with XML:
    • Two applications should agree to a structure. This can be can be defined by xsd
      <Order>
          <from>Swiggy</from>
          <placedon>01/10/2020 18:00:00</placedon>
          <items>
              <item>Biryani Family Pack</item>
              <item>Coke </item>
          </items>
          <delivery>
              <placedon>01/10/2020 18:00:00</placedon>
              <scheduledby>01/10/2020 18:15:00</scheduledby>
          </delivery>
      </Order>
      
      Preview
    • XML as Data Exchange Format is very widely used, but parsing xml is difficult and sizes (payload) of the xml are more in size

Json (JavaScript Object Notation)

  • Data is represented as name value pairs
  • Advantages:
    • It is light weight
    • Easy to read and write
  • Data can be in the form of
    • Text
    • Numbers
    • Boolean
  • Data can be plural or complex
  • Lets try to Think of information, in terms of name value pairs. Lets try to write the info about Bahubali
    • Different Name value pairs Preview
    • If we want to enter data in to the name value pairs the data types could be Preview
  • Basic Json Reprsentation
    • In Json Data is represented as <name>: <value>
    • Eg:
      "Hero": "Prabhas"
      
  • Json Data Types: Value section might have different values. Value Types could be one of
    • String/Text: ”
    • Number
    • Boolean: true/false
    • list: represented in []
    • object (Complex): Describing this type might require some more name value pairs. Represented in { }
  • Lets write a simple json to represent Bahubali
{
  "title": "Bahubali The Begining", 
  "Director": "S.S. Rajamouli",
  "Writer": "Vijayendra Prasad",
  "BoxOfficeInCrores": 600,
  "BudgetInCrores": 180,
  "Released": "10/07/2015",
  "Languages": [ "Telugu", "Tamil", "Malayalam", "Hindi" ],
  "Distributors": {
	"Telugu": "Arka Media Works",
	"Tamil": [ "StudioGreen", "Sri Thenandal Films", "UV Productions"],
	"Hindi": "Dharma Productions",
	"Malayalam": "Global United Media"
  }
}

YAML (YAML Ain’t a Markup Language)

  • This also can be used for data exchanges and configurations
  • Belives in indendation like python
  • YAML is also collection of name value pairs
  • In YAML Data is represented as <name>: <value>
  • The Datatypes for Yaml are same as json.
    • Text is represented in quotes
    • List Items start with –
    • Object will start at the next indendation
  • Example
---
name: 'Bahubali The Begining'
director: 'S.S. Rajamouli'
story: 'Vijayendra Prasad'
BoxOfficeInCrores: 600
BudgetInCrores: 180
Released: '10/07/2015'
Languages:
  - Telugu
  - Hindi
  - Malayalam
  - Tamil
Distributors:
  Telugu: 'Arka Media Works'
  Hindi: 'Dharma Productions'
  Tamil:
    - 'Studio Green'
    - 'Sri Thenandal Films'
    - 'UV Creations'
  Malayalam: 'Global United Media'

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin