dotnet / dotnet/msbuild

[Feature Request]: Add JsonPeek and JsonPatch tasks

Open
#9,260 3 comments 2 reactions 0 assignees View on GitHub
backlog blocked Feature Request Priority:2 triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

### Summary

Add support in MSBuild for handling JSON as structured data, roughly equivalent to the `XmlPeek`, `XmlPoke`, and `XslTransformation` tasks for XML.

### Background and Motivation

The ["Command line evaluation of MSBuild properties"](https://github.com/dotnet/msbuild/issues/3911#issuecomment-1478468822) feature will output JSON and JSON has become at least as common as XML but is not supported in MSBuild code.

### Proposed Feature

Create `JsonPeek` and `JsonPatch` tasks using System.Text.Json.

Like `XmlPeek` and `XslTransformation` (and unlike `XmlPoke`), the `JsonPeek` and `JsonPatch` tasks should accept input content as either strings or files.

### `JsonPeek`

`JsonPeek` would support querying JSON and would depend on a "location path" which should probably conform with the [JSONPath Draft RFC](https://datatracker.ietf.org/doc/html/draft-ietf-jsonpath-base). SQL Server has a definition for [JSON Path Expressions](https://learn.microsoft.com/en-us/sql/relational-databases/json/json-path-expressions-sql-server?view=sql-server-ver16) that seems to follow the RFC and there is a [JsonPath.Net](https://www.nuget.org/packages/JsonPath.Net) implementation.

`JsonPeek` would be equivalent to `XmlPeek`.

### `JsonPatch`

`JsonPatch` would support modifying JSON and would depend on the [JSON Patch Proposed Standard](https://datatracker.ietf.org/doc/html/rfc6902). There is a [JsonPatch.Net](https://www.nuget.org/packages/JsonPatch.Net) implementation. [JSON Patch support in ASP.NET](https://learn.microsoft.com/en-us/aspnet/core/web-api/jsonpatch?view=aspnetcore-7.0) uses Newtonsoft.Json.

The `JsonPatch` task may be considered to be like [`XslTransformation`](https://learn.microsoft.com/en-us/visualstudio/msbuild/xsltransformation-task?view=vs-2022). A weakness of [`XmlPoke`](https://learn.microsoft.com/en-us/visualstudio/msbuild/xmlpoke-task?view=vs-2022) is that it uses XPath to identify a node which it essentially can only replace. Because the patch document for JSON is generally simpler than an XSLT, `JsonPatch` is probably sufficient as an equivalent for both `XmlPoke` and `XslTransformation`.

### Alternative Designs

_No response_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the existing XmlPeek, XmlPoke, and XslTransformation tasks and the System.Text.Json API. Define the task inputs and behavior for string or file content, JSONPath-style querying, and JSON Patch operations; done means both new tasks are implemented with documented, tested behavior consistent with the proposal.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.