JsonSyntaxTree Class
A parsed JSON document.
public sealed class JsonSyntaxTree : SyntaxTreeRemarks
Parsing never throws and never gives up: whatever the text says, the tree reproduces it exactly, and anything wrong with it is reported through JsonSyntaxTree.GetDiagnostics. Comments and trailing commas are accepted and kept.
Example
var tree = JsonSyntaxTree.ParseText("""{ "name": "value" }""");
var name = ((JsonObjectSyntax)tree.GetRoot().Value!).GetMember("name");
Assert.Equal("value", ((JsonStringSyntax)name!.Value).Value);- Inheritance
SyntaxTreeJsonSyntaxTree
Properties
| Name | Description |
|---|---|
| FilePath |
FilePath
JsonSyntaxTree.csMethods
| Name | Description |
|---|---|
| Create(JsonDocumentSyntax, string?) | Creates a tree over root, taking its text from the root itself. |
| GetChanges(JsonSyntaxTree) | Describes how oldTree would have to change to become this one. |
| GetDiagnostics() | Gets every diagnostic in the tree, in source order. |
| GetRoot() | Gets the root of the tree. |
| GetText() | |
| IsEquivalentTo(JsonSyntaxTree?) | Determines whether the two trees have the same structure and text. |
| ParseText(SourceText, string?) | Parses text. |
| ParseText(string, string?) | Parses text. |
| WithChangedText(SourceText) | Returns a tree over newText. |
| WithChanges(TextChange[]) | Returns a tree over this text with changes applied. |
| WithChanges(IEnumerable<TextChange>) | Returns a tree over this text with changes applied. |
| WithRoot(JsonDocumentSyntax) | Returns a tree whose root is root. |
Create(JsonDocumentSyntax, string?)
JsonSyntaxTree.csCreates a tree over root, taking its text from the root itself.
public static JsonSyntaxTree Create(JsonDocumentSyntax root, string? path = null)GetChanges(JsonSyntaxTree)
JsonSyntaxTree.csDescribes how oldTree would have to change to become this one.
public IReadOnlyList<TextChange> GetChanges(JsonSyntaxTree oldTree)GetDiagnostics()
JsonSyntaxTree.csGets every diagnostic in the tree, in source order.
public override IReadOnlyList<Diagnostic> GetDiagnostics()Returns
GetRoot()
JsonSyntaxTree.csGetText()
JsonSyntaxTree.csIsEquivalentTo(JsonSyntaxTree?)
JsonSyntaxTree.csDetermines whether the two trees have the same structure and text.
public bool IsEquivalentTo(JsonSyntaxTree? other)ParseText overloads
ParseText(SourceText, string?)
JsonSyntaxTree.csParses text.
public static JsonSyntaxTree ParseText(SourceText text, string? path = null)ParseText(string, string?)
JsonSyntaxTree.csParses text.
public static JsonSyntaxTree ParseText(string text, string? path = null)WithChangedText(SourceText)
JsonSyntaxTree.csReturns a tree over newText.
public JsonSyntaxTree WithChangedText(SourceText newText)WithChanges overloads
WithChanges(TextChange[])
JsonSyntaxTree.csReturns a tree over this text with changes applied.
public JsonSyntaxTree WithChanges(params TextChange[] changes)WithChanges(IEnumerable<TextChange>)
JsonSyntaxTree.csReturns a tree over this text with changes applied.
public JsonSyntaxTree WithChanges(IEnumerable<TextChange> changes)WithRoot(JsonDocumentSyntax)
JsonSyntaxTree.csReturns a tree whose root is root.
public JsonSyntaxTree WithRoot(JsonDocumentSyntax root)