How do you edit a JSON file in XWiki?

I’m very new to XWiki, and I’m trying to get my first wiki set up. I needed a panel that would have a tree of documents. I tried to follow the Static JSON Tree section from https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/CreatingATreeView/. I created a page for my JSON structure that looks like this:

{{velocity wiki="false"}}
$response.setContentType('application/json')
$jsontool.serialize({"name": "mytree"})
{{/velocity}}

and then in another page I did:

{{velocity}}
#panelheader('myTreePanel')
{{tree reference="mytree"}}
#panelfooter()
{{/velocity}}

This worked, but now there is no way to go back and edit the JSON content because if I go to the page it tries to show it as contentType JSON, and so doesn’t display the edit button. Is there any other way to get to this file? What is the normal procedure here?

Replace “view” with “edit” in the URL. But if you don’t want to do this every time then you can update your code to do this:

{{velocity wiki="false"}}
#if ($xcontext.action == 'get')
  $response.setContentType('application/json')
  $jsontool.serialize({"name": "mytree"})
#else
  This page generates the JSON for my tree.
#end
{{/velocity}}

Changing “view” to “edit” worked in Chrome, though not in Firefox. I then put in your if-else code. Thanks!