Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dson.go: A DSON converter and serializer in Go #17

Closed
muhammadmuzzammil1998 opened this issue Oct 1, 2018 · 7 comments
Closed

dson.go: A DSON converter and serializer in Go #17

muhammadmuzzammil1998 opened this issue Oct 1, 2018 · 7 comments

Comments

@muhammadmuzzammil1998
Copy link
Contributor

muhammadmuzzammil1998 commented Oct 1, 2018

dson.png

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

Hi,
I wrote a new implementation for DSON standard in Go programming language. It's easy to use and implement in a project.

Kindly review https://github.com/muhammadmuzzammil1998/dsongo and add it to the list of libraries of DSON on the website.

dson.go can:

  • Encode from JSON to DSON
  • Decode from DSON to JSON
  • Validate DSON
  • Marshal a Go structure to DSON
  • Unmarshal DSON to a Go structure

Examples


Install dson.go first

$ go get muzzammil.xyz/dsongo

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}]
    }
}

Thanks!

@muhammadmuzzammil1998 muhammadmuzzammil1998 changed the title DSON converter and serializer in Go dson.go: A DSON converter and serializer in Go Oct 1, 2018
@muhammadmuzzammil1998
Copy link
Contributor Author

I had to change it from dson.go to dsongo because go get got confused and thought dson.go is itself a go file. Redirects should work fine now.

@AnEmortalKid
Copy link
Member

added #18 for this, is that the name you'd like or do you want something different for the Contributor part.

@muhammadmuzzammil1998
Copy link
Contributor Author

It's great 😄 Thanks!

@muhammadmuzzammil1998
Copy link
Contributor Author

@AnEmortalKid Please review #19

@AnEmortalKid
Copy link
Member

Reviewed 19! I'll merge it and we can have @vpzomtrrfrt redeploy!

@muhammadmuzzammil1998
Copy link
Contributor Author

When will @vpzomtrrfrt redeploy?

@muhammadmuzzammil1998
Copy link
Contributor Author

I think there has been a confusion... The master branch is not up to date with the dsongo-by-muhammad branch thats why it doesn't show on the website. Please merge them.

I'll make an issue for it.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants