Giter VIP home page Giter VIP logo

kson's Introduction

kson

Specification of a data format (and schema) designed for APIs, aiming to replace JSON.

The KSON schema can be used to describe JSON files.

KSON

KSON tries solving all the issues of JSON:

KSON pros

JSON schema file using regex-like (*, +, [1-3]) syntax to express

KSON schema example

/* description */
{
  /* comment */
  prop1: string,
  prop2: numeric,
  list1*: string
  list2+: {
    itemProp1: {}
    itemProp2?: string
  }
  listOfString: [string],
  listOfString2[]: string,
  yearDigits[2-4]: numeric,
  listOfObjects: [{
  }]
  prop3: {
    .?: string /* any key, optional, type string */
  },
  prop4: {
    .*: * /* 0 or N keys, any type each */
  },
  prop5: {
    .*: * /* 0 or N keys, any type each */
  },
  prop6: ** /* can be anything, any depth */,
  
  /* equivalent to 'prop7: *': */
  prop7,
  prop8: customType
  
  $types:{
    customType: numeric
  }
}

Syntax

  • /**/ : comment

keys

  • . : a(ny) key
  • * : 0 or N
  • + : 1 or N
  • ? : optional (0 or 1)
  • ``

values

  • (type) : json primitive type
  • ** : anything / any depth

Examples

KSON:

  prop1: string,
  prop2: numeric,
  list1*: string
  list2+: {
    itemProp1: {}
    itemProp2?: string
  }
  yearDigits: [2, 0, 1, 9]
}

What's not?

  • KSON is NOT JSON, i.e. can't be parsed by a JSON parser

Why KSON?

JSON pros & cons

pros

  • popularized because of JS front-ends
  • quite intuitive syntax for Java/C programmers: {} = map/object, [] = list/array
  • can be minified

cons

  • everything must be quoted
  • loose primitive types: null, boolean, number, string (and object/array for structures).
  • no comment possible inside JSON
  • no (widely-used) schema (JSON schema is too verbose anyway)

XML

pros

  • namespaces?

cons

  • verbose (repetition of start/end tags)

TODO

kson's People

Contributors

gmathias avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.