Skip to content
/ isjson Public

A tiny Go module for lightweight JSON detection

License

Notifications You must be signed in to change notification settings

dbnski/isjson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

isjson

A tiny Go module for lightweight JSON detection.

Overview

isjson.IsJSON([]byte) provides a fast heuristic to check whether a byte slice looks like a JSON object. If it looks like JSON, it probably is - that's the philosophy. Designed for speed over precision, it's ideal for scenarios where making decisions on appearance is good enough.

Caveats

  • This is a heuristic, not a parser.
  • It won't catch malformed JSON or deeply nested issues.
  • Best used when performance matters and input is reasonably well-formed.
  • Not suitable for strict validation or security-critical contexts.

Example

package main

import (
    "fmt"
    "github.com/dbnski/isjson"
)

func main() {
    good := []byte(`{"hello":"world"}`)
    bad := []byte(`not json at all`)

    fmt.Println("Good input:", isjson.IsJSON(good)) // true
    fmt.Println("Bad input:", isjson.IsJSON(bad))   // false
}

About

A tiny Go module for lightweight JSON detection

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages