minio / simdjson-go

Golang port of simdjson: parsing gigabytes of JSON per second
Apache License 2.0
1.8k stars 85 forks source link

Error when parsing plain null/true/false/number/string #59

Closed martin-sucha closed 2 years ago

martin-sucha commented 2 years ago

According to json specification, plain null, true, false, 10, "string" are all valid JSON documents, but simdjson-go fails with an error when parsing them:

package main

import (
    "fmt"

    "github.com/minio/simdjson-go"
)

func main() {
    for _, input := range []string{"null", "true", "false", "10", `"string"`, `[]`, `{}`} {
        _, err := simdjson.Parse([]byte(input), nil)
        if err != nil {
            fmt.Printf("%s: %v\n", input, err)
        }
    }
}
null: Failed to find all structural indices for stage 1
true: Failed to find all structural indices for stage 1
false: Failed to find all structural indices for stage 1
10: Failed to find all structural indices for stage 1
"string": Failed to find all structural indices for stage 1

I would expect simdjson-go to parse those simple values like all other parsers do or at least to see a mention in the documentation.

klauspost commented 2 years ago

simdjson is for objects or arrays.

It doesn't make sense to use for single values anyway.

martin-sucha commented 2 years ago

simdjson is for objects or arrays.

Okay. Please add it to the docs then, I have opened a pull request for that.

It doesn't make sense to use for single values anyway.

Depends on the use case. For example, my use case is computing a diff of two JSON values. In my case the two values are two huge objects, so I don't need the plain values right now. However, it is not a big leap to imagine arbitrary json values might be useful in that kind of tool.