GithubHelp home page GithubHelp logo

xiatechs / jsonata-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from blues/jsonata-go

8.0 0.0 3.0 415 KB

Open Source Go version of JSONata - with Xiatech

License: MIT License

JavaScript 1.36% Go 97.31% CSS 0.21% HTML 1.12%
data-transformation json

jsonata-go's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsonata-go's Issues

Getting a list of variables

Hello! Is it possible to get a list of variables to evaluate formula? e.g.:
Formula:

$average([accuracy1, accuracy2])

I'd like to get a list:

[]string{"accuracy1", "accuracy2"}

$eval not working as expected

It appears that the $eval doesn't work as expected.

Input

{
  "inputs" : [
	  {
		  "a" : 1,
		  "b" : "{\"c\":11}"
	  },
	  {
		  "a" : 2,
		  "b": "{\"c\":22}"
	  }
  ]
}

and the corresponding jsonata

$map(inputs,function($v){{
  "a": $v.a,
  "b": $v.b,
  "c": $eval($v.b).c
}})

should produce something like this

[
  {
    "a": 1,
    "b": "{\"c\":11}",
    "c": 11
  },
  {
    "a": 2,
    "b": "{\"c\":22}",
    "c": 22
  }
]

instead I am getting,

[
  {
    "a": 1,
    "b": "{\"c\":11}"
  },
  {
    "a": 2,
    "b": "{\"c\":22}"
  }
]

as you can see, "c" is silently failing

Mark variables as obligatory

I'd like to evaluate formula:

$average([accuracy1, accuracy2])

Currently, If I don't set accuracy2, the library will ignore it and return value of accuracy1. Is it possible to mark some/all variables as obligatory?

Example:

expr, err  := jsonata.Compile("$average([accuracy1, accuracy2])")
if err != nil {
	log.Fatal("Invalid expression", err)
	return
}

res, err := expr.Eval(map[string]any{"accuracy1": 0.9}) 

Got result: 0.9, nil.
Wanted result: 0, errUndfinedVariable("accuracy2")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.