# Reply\_json\_dict: avoid losing distinction between atoms and strings

**URL:** <https://swi-prolog.discourse.group/t/reply-json-dict-avoid-losing-distinction-between-atoms-and-strings/299>\
**Category:** Help!\
**Created:** [February 18, 2019, 9:55pm UTC](https://swi-prolog.discourse.group/t/reply-json-dict-avoid-losing-distinction-between-atoms-and-strings/299 "2019-02-18T21:55:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![careyphillips92](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@careyphillips92](https://swi-prolog.discourse.group/u/careyphillips92)\
**Post date:** [February 18, 2019, 9:55pm UTC](https://swi-prolog.discourse.group/t/reply-json-dict-avoid-losing-distinction-between-atoms-and-strings/299/1 "2019-02-18T21:55:14Z")

</div>

I have a dict in my server code that looks like this:

> \_337322{elements:[[name1,alice],[name2,“alice”]]}

After dispatching it off to the client using reply\_json\_dict, it arrives looking like this:

> {  
> “elements”: [[“name1”, “alice”], [“name2”, “alice”] ]  
> }

Atoms and strings both end up mapping onto strings, so crucial information has been lost. (name1 was paired with an atom, name2 was paired with a string.)

Is there some way I can preserve the info? I had a look at the options blurb for reply\_json\_dict/2 but didn’t see anything that would obviously help me.

---

<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:** [February 18, 2019, 11:29pm UTC](https://swi-prolog.discourse.group/t/reply-json-dict-avoid-losing-distinction-between-atoms-and-strings/299/2 "2019-02-18T23:29:22Z")

</div>

If the distinction between atom and string is crucial to you you’ll have to map your data structure into something that preserves this. For example, you could map each atom into \_{type:atom, text:alice}. As is, JSON has only a single string type and the Prolog mapping tries to be in sync what JSON documents typically mean as closely as possible. If you want to represent pure Prolog data I would serialize it using `write_canonical/1`

Note that then Pengines library also provides a JSON representation for arbitrary Prolog terms.
