JqSharp 0.1.0

dotnet add package JqSharp --version 0.1.0
                    
NuGet\Install-Package JqSharp -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JqSharp" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JqSharp" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="JqSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JqSharp --version 0.1.0
                    
#r "nuget: JqSharp, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package JqSharp@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JqSharp&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=JqSharp&version=0.1.0
                    
Install as a Cake Tool

JqSharp

NuGet Build License: MIT

JqSharp is a pure C# implementation of the jq JSON filter language. It is a port of gojq by itchyny: the lexer, parser, compiler, bytecode interpreter and builtins follow gojq file by file, and the error messages are the same as gojq's. The port follows gojq main at 806d7bd (2026-10-31, 59 commits after v0.12.19), so it includes fixes made since that release. It has no dependencies (no System.Text.Json).

Targets netstandard2.0, netstandard2.1, net8.0, and net10.0.

Installation

dotnet add package JqSharp

Usage

using JqSharp;

JqQuery query = JqQuery.Parse(".items[] | select(.price > 10) | .name");
JqCode code = query.Compile();

object? input = JqValue.FromJson("{\"items\": [{\"name\": \"a\", \"price\": 5}, {\"name\": \"b\", \"price\": 20}]}");
foreach (object? value in code.Run(input))
{
    Console.WriteLine(JqValue.ToJson(value)); // "b"
}

Values are null, bool, numbers (long, double, BigInteger, or JsonNumber, which keeps the literal text of a decoded JSON number), string, List<object?> for arrays and Dictionary<string, object?> for objects. Other primitive numbers passed as input (int, float, ...) are converted; any other type (int[], JsonElement, ...) throws an ArgumentException. Outputs can share arrays and objects with the input and with constants of the query, so copy a value before changing it. Enumerating the results of Run again runs the query again.

Errors are JqExceptions: JqParseException for syntax errors, JqValueException for error/1 (with the value), JqHaltException for halt and halt_error. Runtime errors are thrown while enumerating the results.

To bound a query that may not finish (like def f: 1 + f; f from an untrusted user), pass a CancellationToken, the counterpart of gojq's RunWithContext. The token is checked before every interpreter instruction, and enumeration throws an OperationCanceledException once it is canceled:

using CancellationTokenSource cts = new(TimeSpan.FromSeconds(1));
foreach (object? value in code.Run(input, cts.Token)) // or code.Run(input, cts.Token, variableValues)
{
    // ...
}

JqCompilerOptions provides:

  • Variables: names of variables (like $x) whose values are passed to Run.
  • EnvironLoader: the environment for $ENV and env (not visible by default).
  • InputIter: the values input and inputs read.
  • ModuleLoader: an IJqModuleLoader for import and include; JqModuleLoader loads modules from directories.

Differences from gojq

  • The first runtime error ends the enumeration; gojq's iterator can continue after an error.
  • Regular expressions use .NET System.Text.RegularExpressions instead of Go's RE2, so rare syntax and error messages differ (\d, \w, \s and $ follow .NET rules). . matches a whole code point as in RE2, but negated classes such as [^a] or \W can match half of a surrogate pair.
  • Recursion over values and queries runs on the .NET thread stack, so very deep nesting fails with exceeded max depth: about 1,000 to 5,000 levels on a default 1 MB stack (gojq accepts JSON up to 10,000 levels). Run on a thread with a larger stack for deeper data.
  • %Z in strflocaltime prints a numeric zone name (like +09) since .NET does not expose zone abbreviations.
  • Not ported: the gojq command line program (and with it debug, stderr, input_filename), YAML, --stream, --seq, and custom functions (WithFunction, WithIterFunction).

Tests

The tests run the data-driven suite of gojq (cli/test.yaml, converted to tests/JqSharp.Tests/testdata/cli-cases.jsonl) through the library, plus the examples of gojq's query_test.go and compiler_test.go. Cases that need the command line program are listed in CliCaseTests.SkippedCases with the reason.

License

MIT. JqSharp is derived from gojq, Copyright (c) 2019-2026 itchyny, also under the MIT license; see LICENSE. The math functions are ported from the Go standard library (BSD license), and strftime/strptime from timefmt-go (MIT).

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 129 11/1/2026