Coder Social home page Coder Social logo

Comments (10)

kseistrup avatar kseistrup commented on June 11, 2024 1

This seems to have fixed the issue. Thanks for fixing it so swiftly!

from gron.

tomnomnom avatar tomnomnom commented on June 11, 2024 1

I managed to get a few minutes free to sort this.

The changes are available in v0.6.0.

Please let me know if you hit any more problems!

from gron.

tomnomnom avatar tomnomnom commented on June 11, 2024

Hi @kseistrup! Thanks for raising an issue!

It looks like this is actually the default behaviour of Go's encoding/json package (which is used only when the output is not colourised). I'll see about fixing this for you now

from gron.

tomnomnom avatar tomnomnom commented on June 11, 2024

@kseistrup this should be fixed in master now. Are you able to update with go get -u github.com/tomnomnom/gron, or would you like me to upload a binary so you can test?

from gron.

kseistrup avatar kseistrup commented on June 11, 2024

I can go get, so I'll try it right away…

from gron.

kseistrup avatar kseistrup commented on June 11, 2024

While the JSON itself is identical, the new code adds a blank line after the JSON whenever stdout is not a TTY:

$ gron config.json | grep friends
json.friends = {};
json.friends.hops = 3;
$ gron config.json | grep friends | ungron
{
  "friends": {
    "hops": 3
  }
}
$ gron config.json | grep friends | ungron | cat
{
  "friends": {
    "hops": 3
  }
}

$ 

from gron.

rjmunro avatar rjmunro commented on June 11, 2024

In case like me you were wondering what is different about the 2 examples, here is something minimal to illustrate the issue:

$ echo 'json[0] = "&";' | ungron
[
   "&"
]
$ echo 'json[0] = "&";' | ungron | cat
[
  "\u0026"
]

from gron.

kseistrup avatar kseistrup commented on June 11, 2024

Thanks for the minimal example, @rjmunro.

That issue has been solved, but the JSON outputs are still not identical:

$ echo 'json[0]="&";' | ungron
[
  "&"
]
$ echo 'json[0]="&";' | ungron | cat
[
  "&"
]

$ 

from gron.

tomnomnom avatar tomnomnom commented on June 11, 2024

Hey; thanks for reminding me about this!

I'll see if I can get a fix in for it soon. Happy to accept PRs for it too ;)

from gron.

kseistrup avatar kseistrup commented on June 11, 2024

@tomnomnom,

For lists and single elements the indentation is different:

$ echo 3 | gron | ungron
 3
$ echo 3 | gron | ungron | cat
3
$ echo '[1,2,3]' | gron | ungron
[
   1,
   2,
   3
]
$ echo '[1,2,3]' | gron | ungron | cat
[
  1,
  2,
  3
]

Mappings are not affected, though:

$ echo '{"a":true,"b":false}' | gron | ungron
{
  "a": true,
  "b": false
}
$ echo '{"a":true,"b":false}' | gron | ungron | cat
{
  "a": true,
  "b": false
}
$ 

from gron.

Related Issues (20)

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.