tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
14.2k stars 846 forks source link

pretty modifiers are not working as expected #328

Closed 15083787153 closed 1 year ago

15083787153 commented 1 year ago

this is my code

package main
import (
    "fmt"
    "github.com/tidwall/gjson"
)
func main() {

    myStr := `{
    "type": "bundle",
    "id": "bundle--184272f8-fecd-4e23-96b3-c8650e78a5d1",
    "spec_version": "2.0",
    "objects": ["type": "bundle","id": "bundle--184272f8-fecd-4e23-96b3-c8650e78a5d1"]}`

    //first test
    myStr = gjson.Get(myStr, "@pretty:{\"Indent\":\"    \"} ").String()
    fmt.Println(myStr)

    //second test
    myStr = gjson.Get(myStr, `@pretty:{"Indent":"    "}`).String()
    fmt.Println(myStr)
}

I would like to have four spaces, but in both test results, there are only the default two spaces. Looks like the Indent parameter doesn't work。

tidwall commented 1 year ago

try: @pretty:{"indent":" "} (the "indent" has a lowercase 'i')

praveen0raj commented 1 year ago

@15083787153 FYI: you have mentioned key "objects" as an array([]), but It should be with {} . After running above code, its giving wrong output.

Output: { "type": "bundle", "id": "bundle--184272f8-fecd-4e23-96b3-c8650e78a5d1", "spec_version": "2.0", "objects": [ "type", "bundle", "id", "bundle--184272f8-fecd-4e23-96b3-c8650e78a5d1" ] }

Please close this issue as this is case sensitive issue at client end .