Skip to content

Commit

Permalink
add some new features to go-jsonata [xia]
Browse files Browse the repository at this point in the history
  • Loading branch information
tbal999 committed Sep 19, 2022
1 parent 328dbf9 commit 840ede8
Show file tree
Hide file tree
Showing 32 changed files with 86 additions and 58 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ It currently has feature parity with jsonata-js 1.5.4. As well as a most of the

## Install

go get github.com/blues/jsonata-go
go get github.com/xiatechs/jsonata-go

## Usage

Expand All @@ -17,7 +17,7 @@ import (
"fmt"
"log"

jsonata "github.com/blues/jsonata-go"
jsonata "github.com/xiatechs/jsonata-go"
)

const jsonString = `
Expand Down Expand Up @@ -56,7 +56,7 @@ func main() {

## JSONata Server
A locally hosted version of [JSONata Exerciser](http://try.jsonata.org/)
for testing is [available here](https://github.com/blues/jsonata-go/jsonata-server).
for testing is [available here](https://github.com/xiatechs/jsonata-go/jsonata-server).

## JSONata tests
A CLI tool for running jsonata-go against the [JSONata test suite](https://github.com/jsonata-js/jsonata/tree/master/test/test-suite) is [available here](./jsonata-test).
Expand Down
6 changes: 3 additions & 3 deletions callable.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"regexp"
"strings"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jparse"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

type callableName struct {
Expand Down
4 changes: 2 additions & 2 deletions callable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"strings"
"testing"

"github.com/blues/jsonata-go/jparse"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

var (
Expand Down
18 changes: 15 additions & 3 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"strings"
"unicode/utf8"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jparse"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

type environment struct {
Expand Down Expand Up @@ -67,6 +67,18 @@ var (

var baseEnv = initBaseEnv(map[string]Extension{

/*
EXTENDED START
*/
"unescape": {
Func: jlib.Unescape,
UndefinedHandler: defaultUndefinedHandler,
EvalContextHandler: defaultContextHandler,
},
/*
EXTENDED END
*/

// String functions

"string": {
Expand Down
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"regexp"

"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

// ErrUndefined is returned by the evaluation methods when
Expand Down
8 changes: 4 additions & 4 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"reflect"
"sort"

"github.com/blues/jsonata-go/config"
"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jparse"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/config"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
"github.com/shopspring/decimal"
)

Expand Down
6 changes: 3 additions & 3 deletions eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"strings"
"testing"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jparse"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

type evalTestCase struct {
Expand Down
2 changes: 1 addition & 1 deletion example_eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"log"

jsonata "github.com/blues/jsonata-go"
jsonata "github.com/xiatechs/jsonata-go"
)

const jsonString = `
Expand Down
2 changes: 1 addition & 1 deletion example_exts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"log"
"strings"

jsonata "github.com/blues/jsonata-go"
jsonata "github.com/xiatechs/jsonata-go"
)

//
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/blues/jsonata-go
module github.com/xiatechs/jsonata-go

go 1.16

Expand Down
4 changes: 2 additions & 2 deletions jlib/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"fmt"
"reflect"

"github.com/blues/jsonata-go/config"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/config"
"github.com/xiatechs/jsonata-go/jtypes"
"github.com/shopspring/decimal"
)

Expand Down
2 changes: 1 addition & 1 deletion jlib/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"reflect"
"sort"

"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

// Count (golint)
Expand Down
2 changes: 1 addition & 1 deletion jlib/boolean.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package jlib
import (
"reflect"

"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

// Boolean (golint)
Expand Down
4 changes: 2 additions & 2 deletions jlib/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"strconv"
"time"

"github.com/blues/jsonata-go/jlib/jxpath"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib/jxpath"
"github.com/xiatechs/jsonata-go/jtypes"
)

// 2006-01-02T15:04:05.000Z07:00
Expand Down
4 changes: 2 additions & 2 deletions jlib/date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"testing"
"time"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jtypes"
)

func TestFromMillis(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion jlib/hof.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"reflect"

"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

// Map (golint)
Expand Down
2 changes: 1 addition & 1 deletion jlib/jlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"reflect"
"time"

"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion jlib/number.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strconv"
"strings"

"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

var reNumber = regexp.MustCompile(`^-?(([0-9]+))(\.[0-9]+)?([Ee][-+]?[0-9]+)?$`)
Expand Down
4 changes: 2 additions & 2 deletions jlib/number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"fmt"
"testing"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jtypes"
)

func TestRound(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion jlib/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"reflect"

"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

// typeInterfaceMap is the reflect.Type for map[string]interface{}.
Expand Down
4 changes: 2 additions & 2 deletions jlib/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"strings"
"testing"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jtypes"
)

type eachTest struct {
Expand Down
4 changes: 2 additions & 2 deletions jlib/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"strings"
"unicode/utf8"

"github.com/blues/jsonata-go/jlib/jxpath"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib/jxpath"
"github.com/xiatechs/jsonata-go/jtypes"
)

// String converts a JSONata value to a string. Values that are
Expand Down
4 changes: 2 additions & 2 deletions jlib/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"testing"
"unicode/utf8"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jtypes"
)

var typereplaceCallable = reflect.TypeOf((*replaceCallable)(nil)).Elem()
Expand Down
18 changes: 18 additions & 0 deletions jlib/unescape.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package jlib

import (
"fmt"
"encoding/json"
)

// Unescape a string into JSON - simple but powerful
func Unescape(input string) (interface{}, error) {
var output interface{}

err := json.Unmarshal([]byte(input), &output)
if err != nil {
return output, fmt.Errorf("unescape json unmarshal error: %v", err)
}

return output, nil
}
2 changes: 1 addition & 1 deletion jparse/jparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"testing"
"unicode/utf8"

"github.com/blues/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jparse"
)

type testCase struct {
Expand Down
2 changes: 1 addition & 1 deletion jsonata-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ for testing [jsonata-go](https://github.com/blues/jsonata).

## Install

go install github.com/blues/jsonata-go/jsonata-server
go install github.com/xiatechs/jsonata-go/jsonata-server

## Usage

Expand Down
2 changes: 1 addition & 1 deletion jsonata-server/bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"encoding/json"

jsonata "github.com/blues/jsonata-go"
jsonata "github.com/xiatechs/jsonata-go"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions jsonata-server/exts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
package main

import (
"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jtypes"
)

// Default format for dates: e.g. 2006-01-02 15:04 MST
Expand Down
6 changes: 2 additions & 4 deletions jsonata-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
_ "net/http/pprof"
"strings"

jsonata "github.com/blues/jsonata-go"
"github.com/blues/jsonata-go/jtypes"
jsonata "github.com/xiatechs/jsonata-go"
"github.com/xiatechs/jsonata-go/jtypes"
)

func init() {
Expand Down Expand Up @@ -52,7 +52,6 @@ func main() {
}

func evaluate(w http.ResponseWriter, r *http.Request) {

input := strings.TrimSpace(r.FormValue("json"))
if input == "" {
http.Error(w, "Input is empty", http.StatusBadRequest)
Expand All @@ -78,7 +77,6 @@ func evaluate(w http.ResponseWriter, r *http.Request) {
}

func eval(input, expression string) (b []byte, status int, err error) {

defer func() {
if r := recover(); r != nil {
b = nil
Expand Down
4 changes: 2 additions & 2 deletions jsonata-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"regexp"
"strings"

jsonata "github.com/blues/jsonata-go"
types "github.com/blues/jsonata-go/jtypes"
jsonata "github.com/xiatechs/jsonata-go"
types "github.com/xiatechs/jsonata-go/jtypes"
)

type testCase struct {
Expand Down
6 changes: 3 additions & 3 deletions jsonata.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"time"
"unicode"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jparse"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions jsonata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"time"
"unicode/utf8"

"github.com/blues/jsonata-go/jparse"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

type testCase struct {
Expand Down

0 comments on commit 840ede8

Please sign in to comment.