🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More
Socket
Book a DemoSign in
Socket

JsonPath

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

JsonPath

A .NET library for extracting values from JSON with simple expressions, similar to XPath for XML but type-safe. Supports JSON, XML and YAML parsing with intuitive syntax like json[2]["aNumber"] and LINQ integration.

Source
nugetNuGet
Version
2.1.0
Version published
Maintainers
1
Created
Source

JsonPath

A .NET library for extracting values from JSON and XML with simple expressions, similar to XPath for XML but type-safe.

Features

  • Simple JSON Navigation: Extract values with intuitive syntax like json[2]["aNumber"]
  • Type-Safe Operations: Built-in type conversions with .AsInt, .AsString, .AsDictionary, etc.
  • LINQ Integration: Full support for LINQ queries on JSON data
  • XML Support: Parse and navigate XML documents with the same syntax
  • No Exceptions: Invalid paths return default values instead of throwing exceptions
  • Enumerable Support: Iterate over JSON arrays and objects with foreach loops

Quick Start

using JsonPath;

// Parse JSON
var json = Node.FromJson("""
            [
                "1st",
                "2nd",
                {
                    "aString": "Hello World",
                    "aNumber": 42
                }
            ]
            """);

// Extract values
int number = json[2]["aNumber"];                    // 42
string text = json[2]["aString"];                   // "Hello World"
var explicitInt = json[2]["aNumber"].AsInt;         // 42

// Safe navigation - no exceptions for invalid paths
int invalid = json[1000]["noNumber"];               // 0 (default value)

// Iterate over collections
foreach (var pair in json[2]) {
    Console.WriteLine($"{pair.Key} = {pair.Value}");
}

// LINQ support
int result = json[2].Where(x => x.Key == "aNumber").Select(x => x.Value).First();

XML Support

// Parse YAML
var xml = Node.FromXml("""
            <root>
                <item>1st</item>
                <item>2nd</item>
                <item>
                    <aNumber>42</aNumber>
                </item>
            </root>
            """);
var number = xml[Xml.Children][2][Xml.Children]
    .AsList.FirstOrDefault(x => x[Xml.Name] == "aNumber")?[Xml.Text].AsInt;

YAML Support

var xml = Node.FromYaml("""
doc:
    - item: 1st
    - item: 2nd
    - aString: Hello World
      aNumber: 42
""");

int number = json[2]["aNumber"];

Installation

dotnet add package JsonPath

Requirements

  • .NET 8.0 or later
  • Newtonsoft.Json

License

MIT License

Keywords

json

FAQs

Package last updated on 28 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts