# How to extract JSON results (JS driver)

**URL:** <https://community.neo4j.com/t/how-to-extract-json-results-js-driver/67698>\
**Category:** Newbie Questions\
**Created:** [May 2, 2024, 2:18pm UTC](https://community.neo4j.com/t/how-to-extract-json-results-js-driver/67698 "2024-05-02T14:18:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DC1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dc1/32/15764_2.png) [@DC1](https://community.neo4j.com/u/DC1)\
**Post date:** [May 2, 2024, 2:18pm UTC](https://community.neo4j.com/t/how-to-extract-json-results-js-driver/67698/1 "2024-05-02T14:18:20Z")

</div>

based on [this question](https://community.neo4j.com/t/how-to-avoid-duplicate-node-rows-in-a-graph/67458)

How do I get at a JSON result from the query?

I have a cypher query that formats the results. When logging with `(let row of result.records) {`  
I get something like the below. There is JSON there but it's under `_fields[0]` which looks like a private variable I shouldn't just parse.

Is there a way to get something like `result.value` ?

```auto
row 0 Record {
  keys: [
    '{\n' +
      ' graph: {\n' +
      ' nodes: [n in nodes|n{.name}],\n' +
      ' links: [r in rels| {\n' +
      ' name: r.name,\n' +
      ' source: startNode(r).name,\n' +
      ' target: endNode(r).name\n' +
      ' }]\n' +
      ' }\n' +
      ' }'
  ],
  length: 1,
  _fields: [{ graph: [Object] } ],
  _fieldLookup: {
    '{\n graph: {\n nodes: [n in nodes|n{.name}],\n links: [r in rels| {\n name: r.name,\n source: startNode(r).name,\n target: endNode(r).name\n }]\n }\n }': 0
  }
}

```

FWIW my cypher looks something like this:

```auto
    const query = `
      // get all nodes and links for a chapter
      MATCH
        (ch:CHAPTER{uid:$chapterId})-[r1]-> (t1)-[r2]->(t2)
      with
        COLLECT(DISTINCT t1) as nodes,
        collect(DISTINCT r2) as rels
      return {
        graph: {
          nodes: [n in nodes|n{.name}],
          links: [r in rels| {
            name: r.name,
            source: startNode(r).name,
            target: endNode(r).name
          }]
        }
      }`

    const res = await neoConn().runTx(query, {
      chapterId: this.data.id!,
    })

```

---

<div class="post-metadata">

**Author:** ![DC1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dc1/32/15764_2.png) [@DC1](https://community.neo4j.com/u/DC1)\
**Post date:** [May 2, 2024, 2:20pm UTC](https://community.neo4j.com/t/how-to-extract-json-results-js-driver/67698/2 "2024-05-02T14:20:08Z")

</div>

update: copilot gives this which seems to work:

`const val = res.records[0].get(0)`

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [May 3, 2024, 6:27pm UTC](https://community.neo4j.com/t/how-to-extract-json-results-js-driver/67698/3 "2024-05-03T18:27:14Z")

</div>

Yes, because you only have one record in your results since you aggregated everything, so record[0] works. You are returning only one column 'graph', so getting the zeroth item from the record[0] works.
