Error Details

Examples

Below are couple of examples showing errors in queried files as well as in query itself.

Note

For more examples demonstrating errors look at examples in this folder: FailureExamples

Missing closing brace in queried JSON file:

The C# code snippet below queries JSON file Data.json below. The query results in errors since the referenced file has a JsonQL function with missing closing braces.

Queried Data.json file:

{
  "TestData": [ 1, 3, 4, "5", "TEST", 7 ],
  "JsonQlExpressionWithMissinClosingBraces": "$value(ToInt(TestData[3]) + 1"
}
// Set the value of queryManager to an instance of JsonQL.Query.IQueryManager here.
// The value of JsonQL.Query.IQueryManager is normally created by Dependency Injection container
// and it is normally configured as a singleton.
JsonQL.Query.IQueryManager queryManager = null!;

// This query will fail since the value of JSON key "JsonQlExpressionWithMissingClosingBraces"
// is a JsonQL "$value(ToInt(TestData[3]) + 1" that has no closing brace for
// "$value(" function.
var query = "JsonQlExpressionWithMissingClosingBraces";

var queryResult =
    queryManager.QueryJsonValue(query,
        new JsonTextData("Data",
            this.LoadExampleJsonFile("Data.json")));

The result (an instance of JsonQL.Query.IJsonValueQueryResult) is serialized to a Result.json file below.

Click to expand the result of the query in example above (i.e., instance of JsonQL.Query.IJsonValueQueryResult<IReadOnlyList<IEmployee>>) serialized into Result.json
{
  "ParsedValue": null,
  "CompilationErrors":
  {
    "$type": "System.Collections.Generic.List`1[[JsonQL.Compilation.ICompilationErrorItem, JsonQL]], System.Private.CoreLib",
    "$values": [
      {
        "$type": "JsonQL.Compilation.CompilationErrorItem, JsonQL",
        "JsonTextIdentifier": "Data",
        "LineInfo": {
          "$type": "JsonQL.JsonObjects.JsonLineInfo, JsonQL",
          "LineNumber": 3,
          "LinePosition": 53
        },
        "ErrorMessage": "Closing brace ')' is missing."
      }
    ]
  }
}


The screenshot below shows the error details logged using the data in property CompilationErrors in JsonQL.Query.IJsonValueQueryResult.

../../../_images/missing-closing-brace-error1.jpg

Invalid parameters in query

The C# code snippet below queries JSON file Data.json. The query results in errors since the query uses invalid number of parameter in a call to a JsonQL function.

Queried Data.json file:

{
  "TestData": [ 1, 3, 4, "TEST", 7 ]
}
var query = "Lower(TestData[3])";

// Set the value of queryManager to an instance of JsonQL.Query.IQueryManager here.
// The value of JsonQL.Query.IQueryManager is normally created by Dependency Injection container
// and it is normally configured as a singleton.
JsonQL.Query.IQueryManager queryManager = null!;

// This query will succeed.
var queryResult =
    queryManager.QueryJsonValue(query,
        new JsonTextData("Data",
            this.LoadExampleJsonFile("Data.json")));

Assert.That(queryResult.ParsedValue is IParsedSimpleValue {Value: "test"});

// This query will fail as it has extra parameter.
query = "Lower(TestData[3], 7)";

queryResult =
    queryManager.QueryJsonValue(query,
        new JsonTextData("Data",
            this.LoadExampleJsonFile("Data.json")));

The result (an instance of JsonQL.Query.IJsonValueQueryResult) is serialized to a Result.json file below.

Click to expand the result of the query in example above (i.e., instance of JsonQL.Query.IJsonValueQueryResult<IReadOnlyList<IEmployee>>) serialized into Result.json
{
  "ParsedValue": null,
  "CompilationErrors":
  {
    "$type": "System.Collections.Generic.List`1[[JsonQL.Compilation.ICompilationErrorItem, JsonQL]], System.Private.CoreLib",
    "$values": [
      {
        "$type": "JsonQL.Compilation.CompilationErrorItem, JsonQL",
        "JsonTextIdentifier": "Query_849E0817-3256-483D-8E97-01744EBC3F76",
        "LineInfo": {
          "$type": "JsonQL.JsonObjects.JsonLineInfo, JsonQL",
          "LineNumber": 2,
          "LinePosition": 18
        },
        "ErrorMessage": "Too many parameters provided for function [Lower]. Expected at most 1 parameters."
      }
    ]
  }
}


The screenshot below shows the error details logged using the data in property CompilationErrors in JsonQL.Query.IJsonValueQueryResult.

../../../_images/invalid-parameter-error.jpg