# Can't use term\_to\_json/2 because of Pengines sandbox?

**URL:** https://swi-prolog.discourse.group/t/cant-use-term-to-json-2-because-of-pengines-sandbox/743
**Category:** Help!
**Created:** [May 29, 2019, 10:33pm UTC](https://swi-prolog.discourse.group/t/cant-use-term-to-json-2-because-of-pengines-sandbox/743 "2019-05-29T22:33:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![prodog](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@prodog](https://swi-prolog.discourse.group/u/prodog)
#### Post date: [May 29, 2019, 10:33pm UTC](https://swi-prolog.discourse.group/t/cant-use-term-to-json-2-because-of-pengines-sandbox/743/1 "2019-05-29T22:33:23Z")

</div>

I am using SWI-Prolog 8.0.2 on Ubuntu Linux 18.0.4.

I have my Node.JS code that calls into Pengines running now, but instead of getting a JSON object response I am getting what appears to be some kind of “internal” or “native” format that uses `functor` and `args` properties to describe the Prolog result that is generated by a query to my Pengines code:

```prolog
[{"Report":[{"args":[{"args":[{"args":["move_player_to"],"functor":"trigger_action"},{"args":["attic"],"functor":"target"},{"args":["move_to_adjacent_room"],"functor":"prerequisites_list"}],"functor":"details"}],"functor":"prerequisite"}]}]

```

This is what that looks like when the code is run outside of Pengines, directly in the SWI-Prolog console:

```prolog
Report = [prerequisite(details(trigger_action(move_player_to), target(attic), prerequisites_list(move_to_adjacent_room)))].

```

I read the PEngines documentation and it mentions a predicate called `term_to_json/2`:

[http://www.swi-prolog.org/pldoc/doc\_for?object=section('packages/pengines.html')](http://www.swi-prolog.org/pldoc/doc_for?object=section(%27packages/pengines.html%27))

But when I try to use that function from my code I get the following error:

_No permission to call sandboxed `numbervars(\_1040,\_1042,\_1044,\_1046)’  
Reachable from:_  
_findall(\_1068,(maplist(bind\_var,\_1084),numbervars(\_1094,0,\_1098,singletons(true)]),to\_json(\_1094,\_1068)),[\_1120])_  
_term\_to\_json:term\_to\_json(A,B,C)\n\t tsll:term\_to\_json(A,B)_

This puzzles me because I thought `term_to_json/2` was made specifically for Pengines usage? Either way, what is the simplest way for my Node.JS code that calls into Pengines to get a typical JSON object in response from a query instead of the `functor/args` format I am currently getting?

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [May 30, 2019, 10:26am UTC](https://swi-prolog.discourse.group/t/cant-use-term-to-json-2-because-of-pengines-sandbox/743/2 "2019-05-30T10:26:42Z")

</div>

term\_to\_json/2 is called as part of the reply generation outside the sandbox. Nevertheless, there is no reason for numbervars/4 not to be considered safe. Added.

To reply a nice json term, make sure the predicate binds the result to a dict, e.g.

```prolog
Report = json{target:attic, ...}

```

---

<div class="post-metadata">

### Author: ![prodog](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@prodog](https://swi-prolog.discourse.group/u/prodog)
#### Post date: [May 30, 2019, 10:32am UTC](https://swi-prolog.discourse.group/t/cant-use-term-to-json-2-because-of-pengines-sandbox/743/3 "2019-05-30T10:32:40Z")

</div>

Thanks! I’m on SWI-Prolog 8.0.2. I’ll upgrade on the next stable release to get that change.
