mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2026-11-09 04:09:43 -10:00
* chore(deps): strip dependencies Signed-off-by: Dwi Siswanto <[email protected]> * chore: drop stripped dependencies Signed-off-by: Dwi Siswanto <[email protected]> * tests(integration): reduce external service flakiness Signed-off-by: Dwi Siswanto <[email protected]> * refactor(types): replace govalidator ASCII check Signed-off-by: Dwi Siswanto <[email protected]> * chore(trackers): update go-github import path Signed-off-by: Dwi Siswanto <[email protected]> * chore: use our PD wrapper Signed-off-by: Dwi Siswanto <[email protected]> * chore: use our PD cache packages Signed-off-by: Dwi Siswanto <[email protected]> * chore(utils): use x/net publicsuffix Signed-off-by: Dwi Siswanto <[email protected]> * chore(input): decode YAML without invopop/yaml Signed-off-by: Dwi Siswanto <[email protected]> * refactor(yaml): route callers through pkg/utils/yaml Signed-off-by: Dwi Siswanto <[email protected]> * refactor(json): route callers through pkg/utils/json Signed-off-by: Dwi Siswanto <[email protected]> * refactpr(scan): replace Echo handlers with net/http Signed-off-by: Dwi Siswanto <[email protected]> * refactor(server): replace Echo with net/http Signed-off-by: Dwi Siswanto <[email protected]> * refactor(fuzzplayground): replace Echo server with net/http Signed-off-by: Dwi Siswanto <[email protected]> * test: update subdomains testdata Signed-off-by: Dwi Siswanto <[email protected]> * chore(yaml): satisfy lints Signed-off-by: Dwi Siswanto <[email protected]> * fix codeql --------- Signed-off-by: Dwi Siswanto <[email protected]> Co-authored-by: Mzack9999 <[email protected]>
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package dataformat
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/utils/json"
|
|
)
|
|
|
|
// JSON is a JSON encoder
|
|
//
|
|
// For now JSON only supports objects as the root data type
|
|
// and not arrays
|
|
//
|
|
// TODO: Support arrays + other JSON oddities by
|
|
// adding more attributes to the map[string]interface{}
|
|
type JSON struct{}
|
|
|
|
var (
|
|
_ DataFormat = &JSON{}
|
|
)
|
|
|
|
// NewJSON returns a new JSON encoder
|
|
func NewJSON() *JSON {
|
|
return &JSON{}
|
|
}
|
|
|
|
// IsType returns true if the data is JSON encoded
|
|
func (j *JSON) IsType(data string) bool {
|
|
return strings.HasPrefix(data, "{") && strings.HasSuffix(data, "}")
|
|
}
|
|
|
|
// Encode encodes the data into JSON format
|
|
func (j *JSON) Encode(data KV) (string, error) {
|
|
encoded, err := json.Marshal(data.Map)
|
|
return string(encoded), err
|
|
}
|
|
|
|
// Decode decodes the data from JSON format
|
|
func (j *JSON) Decode(data string) (KV, error) {
|
|
var decoded map[string]interface{}
|
|
err := json.Unmarshal([]byte(data), &decoded)
|
|
return KVMap(decoded), err
|
|
}
|
|
|
|
// Name returns the name of the encoder
|
|
func (j *JSON) Name() string {
|
|
return JSONDataFormat
|
|
}
|