GithubHelp home page GithubHelp logo

supercereal's Introduction

SuperCereal is a simple and efficient JSON serialization library for Go. Unlike most other serializers, including Go's json.Marshal and JavaScript's JSON.stringify, it doesn't operate using an intermediary tree data structure. This makes it significantly more efficient in both time and memory. Because it doesn't use third-party non-standard preprocessing, your code remains purely standard & portable Golang.

17x the json.Marshal performance

supercereal.Marshal(func(object *supercereal.Object) {
  object.Put("firstName", "John")
  object.Put("lastName", "Smith")
  object.Put("isAlive", true)
  object.Put("age", 25)
  object.Put("address", func(object *supercereal.Object) {
    object.Put("streetAddress", "21 2nd Street")
    object.Put("city", "New York")
    object.Put("state", "NY")
    object.Put("postalCode", "10021-3100")
  })
  object.Put("phoneNumbers", func(array *supercereal.Array) {
    array.Put(func(object *supercereal.Object) {
      object.Put("type", "home")
      object.Put("number", "212 555-1234")
    })
    array.Put(func(object *supercereal.Object) {
      object.Put("type", "office")
      object.Put("number", "646 555-4567")
    })
    array.Put(func(object *supercereal.Object) {
      object.Put("type", "mobile")
      object.Put("number", "123 456-7890")
    })
  })
  object.Put("children", func(array *supercereal.Array) {})
  object.Put("spouse", nil)
})

Where supercereal.Marshal returns the []byte (here prettified for demonstration):

{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 25,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    },
    {
      "type": "mobile",
      "number": "123 456-7890"
    }
  ],
  "children": [],
  "spouse": null
}

Licensed Zlib © 2017 - 2019

supercereal's People

Contributors

unetworkingab 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.