jsonata-js / jsonata

JSONata query and transformation language - http://jsonata.org
MIT License
2.02k stars 215 forks source link

Alternative to require('jsonta') to be used in server side #169

Closed Souvikray closed 5 years ago

Souvikray commented 6 years ago

I am wrting code for the server side using Python and need jsonata to parse the JSON data.For interfacing between python and javscript, I am using js2py library.It works well for any given Javascript code and processes the result.However when I run the code with the given javascript code for jsonata, it throws an error

Traceback (most recent call last):
  File "/home/souvik/PycharmProjects/ServiceHandler/Testjs.py", line 67, in <module>
    data = js2py.eval_js(data)
  File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/evaljs.py", line 113, in eval_js
    return e.eval(js)
  File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/evaljs.py", line 182, in eval
    self.execute(code, use_compilation_plan=use_compilation_plan)
  File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/evaljs.py", line 177, in execute
    exec(compiled, self._context)
  File "<EvalJS snippet>", line 2, in <module>
  File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/base.py", line 899, in __call__
    return self.call(self.GlobalObject, args)
  File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/base.py", line 1344, in call
    return Js(self.code(*args))
  File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/host/jseval.py", line 42, in Eval
    executor(py_code)
  File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/host/jseval.py", line 49, in executor
    exec(code, globals())
  File "<string>", line 2, in <module>
  File "/home/souvik/utorapp/lib/python3.5/site-packages/js2py/base.py", line 1079, in get
    raise MakeError('ReferenceError', '%s is not defined' % prop)
js2py.internals.simplex.JsException: ReferenceError: require is not defined

It seems the error is generated by 'require(jsonata)'. Since I want jsonata to work on the server side, is there any way to do it?

s100 commented 6 years ago

@Souvikray Can you show the original Python code you're using, and can you show the JavaScript where the error occurred? I'm looking through the jsonata source and distribution but I don't see a place where we do require(jsonata) or require('jsonata') or anything like that... I think a line of code like that is more likely to appear in your code than in ours.

andrew-coleman commented 5 years ago

Please could you try the version 1.6.1 of jsonata-es5.js and reopen this if you still have problems? Thanks