# How to get JSON path in syntaxTree

**URL:** https://discuss.codemirror.net/t/how-to-get-json-path-in-syntaxtree/6369
**Category:** v6
**Created:** [April 26, 2023, 6:18am UTC](https://discuss.codemirror.net/t/how-to-get-json-path-in-syntaxtree/6369 "2023-04-26T06:18:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![saewitz](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/saewitz/32/3286_2.png) [@saewitz](https://discuss.codemirror.net/u/saewitz)
#### Post date: [April 26, 2023, 6:18am UTC](https://discuss.codemirror.net/t/how-to-get-json-path-in-syntaxtree/6369/1 "2023-04-26T06:18:31Z")

</div>

Hi, I am trying to get the path for an iteration of a syntaxTree in CodeMirror v6. I have this code:

```auto
syntaxTree(view.state)
      .cursor()
      .iterate((node) => {
        console.log(view.state.doc.sliceString(node.from, node.to));
      });

```

which loops through a syntax tree and outputs the JSON attributes. However, this doesn’t give the path to the node. Outputting `node.name` gives values like `JsonText`, `PropertyName`, `Object`, `Property`, and not a JSON path.

I am trying to output the path of the current `node`. So if I had JSON like `{"names": ["example"]}` on an iteration that outputs `"example"` I would get `names[0]`. Is there a way to do this?

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)
#### Post date: [April 26, 2023, 6:51am UTC](https://discuss.codemirror.net/t/how-to-get-json-path-in-syntaxtree/6369/2 "2023-04-26T06:51:24Z")

</div>

Following `.parent` pointers might be what you want. (Though you might want to use a `SyntaxNode` rather than a stateful cursor for that.)
