muhammadmuzzammil1998 / Dsongo

Licence: mit
Encoding, decoding, marshaling, unmarshaling, and verification of the DSON (Doge Serialized Object Notation)

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Dsongo

Mini Yaml
Single header YAML 1.0 C++11 serializer/deserializer.
Stars: ✭ 79 (+243.48%)
Mutual labels:  serializer, parser
Rdflib
RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
Stars: ✭ 1,584 (+6786.96%)
Mutual labels:  serializer, parser
Udt
UDT spec, reference library and related packages
Stars: ✭ 89 (+286.96%)
Mutual labels:  serializer, parser
Serd
A lightweight C library for RDF syntax
Stars: ✭ 43 (+86.96%)
Mutual labels:  serializer, parser
Sparql.js
A parser for the SPARQL query language in JavaScript
Stars: ✭ 271 (+1078.26%)
Mutual labels:  serializer, parser
Go
A high-performance 100% compatible drop-in replacement of "encoding/json"
Stars: ✭ 10,248 (+44456.52%)
Mutual labels:  serializer, parser
Java
jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go
Stars: ✭ 1,308 (+5586.96%)
Mutual labels:  serializer, parser
Parse5
HTML parsing/serialization toolset for Node.js. WHATWG HTML Living Standard (aka HTML5)-compliant.
Stars: ✭ 2,778 (+11978.26%)
Mutual labels:  serializer, parser
Rdflib Jsonld
JSON-LD parser and serializer plugins for RDFLib (Python 2.6+)
Stars: ✭ 250 (+986.96%)
Mutual labels:  serializer, parser
Pxi
🧚 pxi (pixie) is a small, fast, and magical command-line data processor similar to jq, mlr, and awk.
Stars: ✭ 248 (+978.26%)
Mutual labels:  serializer, parser
Tomlplusplus
Header-only TOML config file parser and serializer for C++17 (and later!).
Stars: ✭ 403 (+1652.17%)
Mutual labels:  serializer, parser
Toml11
TOML for Modern C++
Stars: ✭ 390 (+1595.65%)
Mutual labels:  serializer, parser
N3.js
Lightning fast, spec-compatible, streaming RDF for JavaScript
Stars: ✭ 521 (+2165.22%)
Mutual labels:  serializer, parser
Markdown Wasm
Markdown parser and HTML generator implemented in WebAssembly, based on md4c
Stars: ✭ 833 (+3521.74%)
Mutual labels:  parser
Rfdmovies Client
🎬instant recommending or finding or downloading movies via the command line
Stars: ✭ 18 (-21.74%)
Mutual labels:  parser
Proposal Binary Ast
Binary AST proposal for ECMAScript
Stars: ✭ 831 (+3513.04%)
Mutual labels:  parser
Imdbpy
IMDbPY is a Python package useful to retrieve and manage the data of the IMDb movie database about movies, people, characters and companies
Stars: ✭ 792 (+3343.48%)
Mutual labels:  parser
Combine
A parser combinator library for Rust
Stars: ✭ 906 (+3839.13%)
Mutual labels:  parser
Arg
Simple argument parsing
Stars: ✭ 897 (+3800%)
Mutual labels:  parser
Php Parser
PHP parser written in Go
Stars: ✭ 787 (+3321.74%)
Mutual labels:  parser

dson.png

Build Status CodeFactor Go Report Card Codacy Badge Maintainability Test Coverage GitHub license Twitter

dson.go provides encoding, decoding, marshaling, unmarshaling, and verification of the DSON (Doge Serialized Object Notation) as defined here.

Index

Installing dson.go package

go get muzzammil.xyz/dsongo

Documentation

Syntax

DSON is built on two structures:

  • A collection of key/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.

  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

Keys and Values

A key is a string in double quotes.

A value can be a string in double quotes, or a number, or yes or no or empty, or an object or an array. These structures can be nested.

such
  "foo" is "bar"
wow

is equivalent to this in JSON:

{
  "foo": "bar"
}

Strings

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes.

Numbers

A number is very much like a C or Java number, except it is presented in the dog-friendly octal base.

Objects

An object begins with such and ends with wow. Each key is followed by is and the key/value pairs are separated by , (comma) or . (dot) or ! or ?.

such
  "foo" is "bar",
  "number" is 42!
  "alive" is yes
wow

is equivalent to this in JSON:

{
  "foo": "bar",
  "number": 34,
  "alive": true
}

Arrays

An array begins with so and ends with many. Values are separated by and or also.

such
  "ID" is 1!
  "Name" is "Reds".
  "Colors" is so
    "Crimson" and "Red" and "Ruby" also "Maroon"
  many
wow

is equivalent to this in JSON:

{
  "id": 1,
  "Name": "Reds",
  "Colors": ["Crimson", "Red", "Ruby", "Maroon"]
}

Examples

Common imports

import (
    "fmt"

    "muzzammil.xyz/dsongo"
)

Encoding JSON into DSON

func main() {
    d := dson.Encode(`{"foo":"bar"}`)
    fmt.Println(d) // such "foo" is "bar" wow
}

Decoding DSON into JSON

func main() {
    j := dson.Decode(`such "foo" is "bar" wow`)
    fmt.Println(j) // {"foo":"bar"}
}

Validating DSON

func main() {
    if dson.Valid(`such "foo" is "bar" wow`) {
        fmt.Println("Valid DSON")
    } else {
        fmt.Println("Invalid DSON")
    }
}

Marshaling DSON

func main() {
    type ColorGroup struct {
        ID     int
        Name   string
        Colors []string
    }
    RedGroup := ColorGroup{
        ID:     1,
        Name:   "Reds",
        Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},
    }
    r, err := dson.Marshal(RedGroup)
    if err == nil && dson.Valid(r) {
        fmt.Println(r) // such "ID" is 1! "Name" is "Reds". "Colors" is so "Crimson" and "Red" and "Ruby" also "Maroon" many wow
    }
}

Unmarshaling DSON

func main() {
    d := `so such "Name" is "Platypus" and "Order" is "Monotremata" wow and such "Name" is "Quoll" and "Order" is "Dasyuromorphia" wow many`
    if !dson.Valid(d) {
        fmt.Println("DSON is not valid")
        return
    }
    type Animal struct {
        Name  string
        Order string
    }
    var animals []Animal
    err := dson.Unmarshal(d, &animals)
    if err == nil {
        fmt.Printf("%+v", animals) // [{Name:Platypus Order:Monotremata} {Name:Quoll Order:Dasyuromorphia}]
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].