# How can I get query answers back in JSON format?

**URL:** <https://forum.typedb.com/t/how-can-i-get-query-answers-back-in-json-format/107>\
**Category:** TypeDB\
**Tags:** typedb-client-api, typedb-client-nodejs\
**Created:** [7 April 2022 13:54 UTC](https://forum.typedb.com/t/how-can-i-get-query-answers-back-in-json-format/107 "2022-04-07T13:54:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/alex/32/148_2.png) [@alex](https://forum.typedb.com/u/alex)\
**Post date:** [7 April 2022 13:54 UTC](https://forum.typedb.com/t/how-can-i-get-query-answers-back-in-json-format/107/1 "2022-04-07T13:54:38Z")

</div>

When passing an arbitrary `match` query to TypeDB using [Client Node.js](https://docs.vaticle.com/docs/client-api/nodejs#execute-a-typeql-match-query), how can I get back a JSON view of the answers that represents them in a canonical format, including e.g:

- whether they are entities, relations, attributes;
- for attributes, include the value

The default return type of a `match` query is an `Iterator` of `ConceptMap`.

---

<div class="post-metadata">

**Author:** ![alex](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/alex/32/148_2.png) [@alex](https://forum.typedb.com/u/alex)\
**Post date:** [7 April 2022 14:00 UTC](https://forum.typedb.com/t/how-can-i-get-query-answers-back-in-json-format/107/2 "2022-04-07T14:00:35Z")

</div>

The answers retrieved from a `match` query can be any kind of Concept. Concepts are structured using a strict type hierarchy:

 ![Concept type hierarchy](https://europe1.discourse-cdn.com/flex005/uploads/vaticle/original/1X/cd7f95d5af6b58f353d587ac3e0f13678b4748a9.png)  
In order to obtain a canonical representation of an arbitrary Concept, we must check what subtype of Concept it is, and then deserialise accordingly.

```javascript
function conceptMapsToJSON(conceptMaps) {
  return conceptMaps.map(x => conceptMapToJSON(x));
}
function conceptMapToJSON(conceptMap) {
  return Object.fromEntries(Array.from(conceptMap.map.entries()).map([varName, concept]) => [varName, conceptToJSON(concept)]));
}
function conceptToJSON(concept) {
  if (concept.isType()) return typeToJSON(type);
  else { throw "TODO: Not implemented yet"; }
}
function typeToJSON(type) {
  if (type.isEntityType()) return entityTypeToJSON(type);
  else { throw "TODO: Not implemented yet"; } // TODO: if (type.isRelationType()), etc.
}
function entityTypeToJSON(entityType) {
  return {
    label: entityType.label.name,
    encoding: "ENTITY_TYPE",
  }
}

```

These methods can be modified as appropriate to get the data in the exact format we want.
