Search notes:

Python library: py_mini_racer

py_mini_racer allows to use the Javascript engine V8 from Python.

Installation with pip

pip3 install py-mini-racer

Evaluating and executing a variable

eval() returns a scalar, execute() is able to return an object:
from py_mini_racer import MiniRacer

js = """
let v = {
   "txt": "Hello world",
   "num":  42,
   "val": [
     [1, 2, 3],
     [4, 5, 6]
    ]
};
"""

ctx = MiniRacer()

ctx.eval(js)

print(ctx.eval('v.val[1][2]'))
print(ctx.eval('v.txt'))
print(ctx.eval('v.num'))

for r in ctx.execute('v.val'):
    for c in r:
        print(c)

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758206323, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/libraries/py_mini_racer(64): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78