Goldie: Parse Tree Mode
Parsing System (v0.9)
Goldie Home (v0.9) -> Goldie's Tools -> JsonViewer -> Parse Tree Mode

Parse Tree Mode

The version of JsonViewer included with Goldie has been customized to include a special Parse Tree Mode for viewing a text document side-by-side with a JSON-based tree that describes the text. In this mode, you can click on a tree node to highlight its corresponding text, or jump from a location in the text to the corresponding tree node.

This page describes the special data JsonViewer looks for to enable and use this mode.

Sample

Goldie includes the sample JSON file jsonSample.json that demonstrates how to create a JSON file that JsonViewer's Parse Tree Mode can use. Here is the content of the file:

{ parseTreeMode: true, source: "Once upon a time...", "Story": { srcIndexStart: 0, srcLength: 19, "Sentence": { srcIndexStart: 0, srcLength: 16, "Word 1": { srcIndexStart: 0, srcLength: 4, }, "Word 2": { srcIndexStart: 5, srcLength: 4, }, "Word 3": { srcIndexStart: 10, srcLength: 1, }, "Word 4": { srcIndexStart: 12, srcLength: 4, } }, "Punctuation": { srcIndexStart: 16, srcLength: 3, } } }

If you load that file into JsonViewer, it will look like this:

As you can see, this JSON file describes a text file containing Once upon a time.... It also tells JsonViewer that Once upon a time is a "Story", ... is "Punctuation", and Once though time are "Word 1" through "Word 4". (Remember that JSON objects can't have multiple members with the same name.)

Click a tree node in the left panel to highlight the corresponding section of text. Click a location in the text and then click "Jump to Node" to select the corresponding node.

Reference

All of the following are optional. However, if none of them are used, then Parse Tree Mode won't be particularly useful.

parseTreeMode

This can go in either the root JSON object (as in the example above), or the first JSON object immediately inside the root ("Story" in the example above).

Giving this a value of true instructs JsonViewer to automatically turn on Parse Tree Mode when loading the file.

source

This can go in either the root JSON object (as in the example above), or the first JSON object immediately inside the root ("Story" in the example above).

This contains the actual text that the JSON file describes. This text will be shown in the middle panel. Don't forget to properly escape any double-quotes.

file

Not recommended: Use source instead.

This can go in either the root JSON object, or the first JSON object immediately inside the root ("Story" in the example above).

If source is omitted, then file can be used to load the source text from a specific file. The value of this should be the filename containing the text that the JSON file describes.

This is NOT recommended, however, because the two files may become out-of-sync. It is recommended that you use source instead. (This can be safely included in addition to source though, because if source is included, JsonViewer will simply ignore file.)

srcIndexStart
srcLength

Any JSON object that includes both srcIndexStart and srcLength is considered to refer to a specific section of the text. This section of the text starts at srcIndexStart (zero-indexed) and extends for srcLength characters.