winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.78k stars 189 forks source link

Json: Equality, diff and patch #3140

Open staycoolcall911 opened 1 year ago

staycoolcall911 commented 1 year ago

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.

github-actions[bot] commented 10 months ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 8 months ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 3 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 2 weeks ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!