GithubHelp home page GithubHelp logo

go-prettyjson's Introduction

prettyjson

JSON pretty print for Golang.

Example

import "github.com/hokaccha/go-prettyjson"

v := map[string]interface{}{
    "str": "foo",
    "num": 100,
    "bool": false,
    "null": nil,
    "array": []string{"foo", "bar", "baz"},
    "map": map[string]interface{}{
        "foo": "bar",
    },
}
s, _ := prettyjson.Marshal(v)
fmt.Println(string(s))

Output

License

MIT

go-prettyjson's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

go-prettyjson's Issues

No `Ugly` Function

It would be useful to have an ugly function so that we can strip all of the formatting, color, etc.

It is an incredible trouble when the given value is prettyjson.Marshal'd and has all the ANSI characters included

Add LICENSE file

Can we add a LICENSE file to this project? It says in README.md that this project uses the MIT license but that should also be reflected in a LICENSE file.

1-line output appears too dense

Hi @hokaccha. Thanks for providing this library!

Here's a thought: when using the 1-line formatter, as shown in this example, the output appears too dense, especially if we want to format deeper-nested structures.

Example output:

["a","b","c"]

Desired output:

[ "a", "b", "c" ]

When I use a f.Indent = 1, the output looks like this (it is understandable though that this won't produce the desired result):

[ "a", "b", "c"]

Any ideas? Thanks, Martin

Field order doesn't match struct

I've just noticed that fields outputted are ordered alphabetically which doesn't follow the convention of the encoding/json library. Ideally, this would be the same as the stdlib json package which outputs fields in the order they are defined in the struct.

filter out

any way to filter?
I try doing this and nothing shows up:

tail -n 10 /home/service/nohup.out -f | grep "text" | zap-pretty

If I don't use grep it all work fine.

Producing non valid JSON if string contains `%` character

Because of using fmt.Sprintf on strings for coloring purposes we have this:

$ cat main.go
package main

import (
    "fmt"
    "github.com/hokaccha/go-prettyjson"
)

func main() {

    v := map[string]interface{}{
        "str":   "foo",
        "num":   100,
        "bool":  false,
        "null":  nil,
        "array": []string{"foo", "bar", "baz"},
        "map": map[string]interface{}{
            "foo":            "bar",
            "my little json": "percents are % magick!",
        },
    }
    s, _ := prettyjson.Marshal(v)
    fmt.Println(string(s))

}
$ go run main.go
{
  "array": [
    "foo",
    "bar",
    "baz"
  ],
  "bool": false,
  "map": {
    "foo": "bar",
    "my little json": "percents are %!m(MISSING)agick!"
  },
  "null": null,
  "num": 100,
  "str": "foo"
}

Look at the !m(MISSING) part.

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.