-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
512c57e
commit cf6e6da
Showing
12 changed files
with
144 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@page "/json-path" | ||
@using LearnJsonEverything.Services.Runners | ||
|
||
<Teacher LessonSource="/data/lessons/path.yaml" Host="@_host"></Teacher> | ||
|
||
@code { | ||
private readonly ILessonHost _host = new PathHost(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
@page "/json-schema" | ||
@using LearnJsonEverything.Services.Runners | ||
|
||
<Teacher LessonSource="/data/lessons/schema.yaml"></Teacher> | ||
<Teacher LessonSource="/data/lessons/schema.yaml" Host="@_host"></Teacher> | ||
|
||
@code { | ||
|
||
private readonly ILessonHost _host = new SchemaHost(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace LearnJsonEverything.Services.Runners; | ||
|
||
public interface ILessonHost | ||
{ | ||
string[] Run(LessonData lesson); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Json.More; | ||
using Json.Path; | ||
|
||
namespace LearnJsonEverything.Services.Runners; | ||
|
||
public class PathHost : ILessonHost | ||
{ | ||
public string[] Run(LessonData lesson) | ||
{ | ||
var (runner, errors) = CompilationHelpers.GetRunner<PathResult>(lesson); | ||
|
||
if (runner is null) return errors; | ||
|
||
var results = new List<string>(); | ||
|
||
var correct = true; | ||
foreach (var test in lesson.Tests) | ||
{ | ||
var expectedResult = test!["result"]; | ||
var result = runner.Run(test.AsObject()); | ||
var localResult = expectedResult.IsEquivalentTo(result.Matches?.Select(x => x.Value).ToJsonArray()); | ||
correct &= localResult; | ||
results.Add($"{(localResult ? Iconography.SuccessIcon : Iconography.ErrorIcon)} {test["data"]!.Print()}"); | ||
} | ||
|
||
lesson.Achieved |= correct; | ||
|
||
return [.. results]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
- id: 26b6ebca-58e6-4814-86ea-494ed844c9a8 | ||
background: | | ||
JSON Path is a syntax for querying JSON data. | ||
_JsonPath.Net_ provides an implementation that conforms to the official IETF | ||
specification, [RFC 9535](https://www.rfc-editor.org/rfc/rfc9535.html). Like the other | ||
guides on this site, this guide will teach you how to use the library _JsonPath.Net_. | ||
However, because there are so few implementations of the RFC, and little to no | ||
documentation of it, this guide will also teach you the features of JSON Path itself, | ||
as described by the RFC. | ||
We'll start with the library since there is less to cover, then we'll move on to | ||
what you can do with it. | ||
Unlike JSON Schema, JSON Logic, or other technologies that are actually represented in | ||
JSON, JSON Path is its own syntax, so it must usually be parsed. The primary way to | ||
parse a path is using the static `JsonPath.Parse()` method. | ||
docs: 'path/basics' | ||
title: Parsing | ||
instructions: | | ||
Parse the given JSON Path text into a `path` variable. | ||
inputTemplate: '' | ||
contextCode: |- | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Json.Path; | ||
namespace LearnJsonEverything; | ||
public class Lesson : ILessonRunner<PathResult> | ||
{ | ||
public PathResult Run(JsonObject test) | ||
{ | ||
var data = test["data"]; | ||
var pathText = "$.foo.bar"; | ||
/* USER CODE */ | ||
return path.Evaluate(data); | ||
} | ||
} | ||
solution: |- | ||
var path = JsonPath.Parse(pathText); | ||
tests: | ||
- data: { "foo": { "bar": "a string" } } | ||
result: ['a string'] |