Skip to content

Commit aa63252

Browse files
cursoragentsimbo1905
andcommitted
Issue #130 Add json-transforms module docs and Maven wiring
Co-authored-by: simbo1905 <simbo1905@60hertz.com>
1 parent 4e125de commit aa63252

File tree

4 files changed

+163
-0
lines changed

4 files changed

+163
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,23 @@ System.out.println("Avg price: " + priceStats.getAverage());
440440

441441
See `json-java21-jsonpath/README.md` for JsonPath operators and more examples.
442442

443+
## json-transforms
444+
445+
This repo includes **json-transforms** (module `json-transforms`): a Java 21 implementation of Microsoft’s *json-document-transforms* specification, which defines JSON-to-JSON transforms using `@jdt.*` verbs (`remove`, `replace`, `merge`, `rename`) plus JSONPath selectors.
446+
447+
```java
448+
import jdk.sandbox.java.util.json.Json;
449+
import json.java21.transforms.JsonTransform;
450+
451+
var source = Json.parse("{\"A\": 1, \"B\": 2}");
452+
var transform = Json.parse("{\"@jdt.remove\": \"A\"}");
453+
454+
var program = JsonTransform.parse(transform); // parse/compile once
455+
var result = program.run(source); // run many times
456+
```
457+
458+
See `json-transforms/README.md` for the supported syntax and more examples.
459+
443460
## Contributing
444461

445462
If you use an AI assistant while contributing, ensure it follows the contributor/agent workflow rules in `AGENTS.md`.

json-transforms/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# json-transforms
2+
3+
This module implements **json-transforms**: JSON-to-JSON transformations defined by a JSON “transform” document applied to a JSON “source” document.
4+
5+
This is based on Microsoft’s *json-document-transforms* specification:
6+
- Wiki/spec: `https://github.com/Microsoft/json-document-transforms/wiki`
7+
- Reference implementation (C#): `https://github.com/microsoft/json-document-transforms`
8+
9+
Important naming note:
10+
- We refer to this technology as **json-transforms** in this repository (to avoid ambiguity with other unrelated acronyms).
11+
- The specification’s on-the-wire syntax uses the literal keys `@jdt.*` (for example `@jdt.remove`), and this implementation follows that syntax for compatibility.
12+
13+
## Quick Start
14+
15+
This library has a **parse/run split** so transform parsing (including JSONPath compilation) can be reused across documents:
16+
17+
```java
18+
import jdk.sandbox.java.util.json.Json;
19+
import json.java21.transforms.JsonTransform;
20+
21+
var source = Json.parse("""
22+
{ "Settings": { "A": 1, "B": 2 }, "Keep": true }
23+
""");
24+
25+
var transform = Json.parse("""
26+
{
27+
"Settings": { "@jdt.remove": "A" }
28+
}
29+
""");
30+
31+
var program = JsonTransform.parse(transform); // parse/compile once (reusable + thread-safe)
32+
var result = program.run(source); // run (immutable result)
33+
```
34+
35+
## Supported Syntax (Spec)
36+
37+
This module follows the Microsoft wiki spec:
38+
- **Default transform**: merge transform object into source object
39+
- **Verbs** (object keys, case-sensitive):
40+
- `@jdt.remove`
41+
- `@jdt.replace`
42+
- `@jdt.merge`
43+
- `@jdt.rename`
44+
- **Attributes** (inside a verb object, case-sensitive):
45+
- `@jdt.path` (JSONPath selector)
46+
- `@jdt.value` (the value to apply)
47+
48+
See the wiki pages for details and examples:
49+
- `Default Transformation`
50+
- `Transform Attributes`
51+
- `Transform Verbs` (Remove/Replace/Merge/Rename)
52+
- `Order of Execution`
53+

json-transforms/pom.xml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<parent>
9+
<groupId>io.github.simbo1905.json</groupId>
10+
<artifactId>parent</artifactId>
11+
<version>0.1.9</version>
12+
</parent>
13+
14+
<artifactId>java.util.json.transforms</artifactId>
15+
<packaging>jar</packaging>
16+
<name>java.util.json Java21 Backport JSON Transforms</name>
17+
<url>https://simbo1905.github.io/java.util.json.Java21/</url>
18+
<scm>
19+
<connection>scm:git:https://github.com/simbo1905/java.util.json.Java21.git</connection>
20+
<developerConnection>scm:git:git@github.com:simbo1905/java.util.json.Java21.git</developerConnection>
21+
<url>https://github.com/simbo1905/java.util.json.Java21</url>
22+
<tag>HEAD</tag>
23+
</scm>
24+
<description>json-transforms implementation for the java.util.json Java 21 backport; parses transform JSON to an immutable program and applies it to JSON documents using JSONPath selectors.</description>
25+
26+
<properties>
27+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
28+
<maven.compiler.release>21</maven.compiler.release>
29+
</properties>
30+
31+
<dependencies>
32+
<dependency>
33+
<groupId>io.github.simbo1905.json</groupId>
34+
<artifactId>java.util.json</artifactId>
35+
<version>${project.version}</version>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>io.github.simbo1905.json</groupId>
40+
<artifactId>java.util.json.jsonpath</artifactId>
41+
<version>${project.version}</version>
42+
</dependency>
43+
44+
<!-- Test dependencies -->
45+
<dependency>
46+
<groupId>org.junit.jupiter</groupId>
47+
<artifactId>junit-jupiter-api</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.junit.jupiter</groupId>
52+
<artifactId>junit-jupiter-engine</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.junit.jupiter</groupId>
57+
<artifactId>junit-jupiter-params</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.assertj</groupId>
62+
<artifactId>assertj-core</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
</dependencies>
66+
67+
<build>
68+
<plugins>
69+
<!-- Treat all warnings as errors, enable all lint warnings -->
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-compiler-plugin</artifactId>
73+
<configuration>
74+
<release>21</release>
75+
<compilerArgs>
76+
<arg>-Xlint:all</arg>
77+
<arg>-Werror</arg>
78+
<arg>-Xdiags:verbose</arg>
79+
</compilerArgs>
80+
</configuration>
81+
</plugin>
82+
<plugin>
83+
<groupId>org.apache.maven.plugins</groupId>
84+
<artifactId>maven-surefire-plugin</artifactId>
85+
<configuration>
86+
<argLine>-ea</argLine>
87+
</configuration>
88+
</plugin>
89+
</plugins>
90+
</build>
91+
</project>
92+

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<module>json-compatibility-suite</module>
4343
<module>json-java21-jtd</module>
4444
<module>json-java21-jsonpath</module>
45+
<module>json-transforms</module>
4546
</modules>
4647

4748
<properties>

0 commit comments

Comments
 (0)