Open
Description
The following section should be added to the language reference:
1.1.4.10 Equality, diff and patch
The Json.equals(lhs: Json, rhs: Json): bool
static method can be used to determine if two values
are equal (recursively comparing arrays and objects):
assert(Json.equals(jsonString, Json "hello"));
assert(Json.equals(jsonObj, { boom: [ 1, 2, 3 ] }));
assert(!Json.equals(Json { hello: [ 1, 2, 3 ] }, Json { hello: [ 1, 2 ] }));
The Json.diff(lhs: Json, rhs: Json): JsonPatch
static method can be used to calculate the deep
difference between two JSON values. It returns a list of differences in
json-patch format (P2).
let j1 = Json {
baz: "qux",
foo: "bar"
};
let j2 = Json {
baz: "boo",
hello: ["world"]
};
assert(Json.diff(j1, j2) = [
{ op: JsonPatch.REPLACE, path: "/baz", value: "boo" },
{ op: JsonPatch.ADD, path: "/hello", value: ["world"] },
{ op: JsonPatch.REMOVE, path: "/foo" }
]);
The Json.patch(j: Json, patch: JsonPatch): Json
static method applies a JsonPatch
to a Json
object.
Metadata
Metadata
Assignees
Type
Projects
Status
Todo - out of scope for beta
Status
🤝 Backlog - handoff to owners