32 lines
617 B
Go
Executable File
32 lines
617 B
Go
Executable File
package exporters
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/ashb/jqrepl/jq"
|
|
)
|
|
|
|
func jQOnJSONByteArray(command string, jsonByteArray []byte) []byte {
|
|
jqInForm, err := jq.JvFromJSONBytes(jsonByteArray)
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
jqObj, err := jq.New()
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
errs := jqObj.Compile(command, jq.JvArray())
|
|
if errs != nil {
|
|
for _, e := range errs {
|
|
fmt.Printf("E: %s\n", e.Error())
|
|
}
|
|
panic("Errors above!")
|
|
}
|
|
jQForm, err := jqObj.Execute(jqInForm)
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
finalJSONForm := []byte(jQForm[0].Dump(jq.JvPrintNone))
|
|
return finalJSONForm
|
|
}
|