---
schema_version: "1"
id: e5fc53da9a0cfa44a611e7903e916b6d4b21b3d890dacb52f952f75fe547daf6
title: diff
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.3/dw-diff-functions-diff.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.3/dw-diff-functions-diff
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ed3c16e3f7b3d59062bae0ff6d3b0ea2e702e127df55475e948ae07205d63235
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
# diff

## [](#diff1)diff(Any, Any, ​{ unordered?: Boolean }, String): Diff

2 つの値の構造的な違いを返します。

オブジェクト間の違いは、順序あり (デフォルト) または順序なしにできます。順序ありにすると、2 つのオブジェクトはキー - 値ペアが同じ順序である場合に、異なっていないと見なされます。違いは ​`Difference`​ 型として表現されます。

### [](#パラメーター)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>actual</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">実際の値。任意のデータ型を使用できます。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>expected</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">実際の値と比較する期待値。任意のデータ型を使用できます。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>diffConfig</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​{ "unordered" : true}​ を使用して、デフォルトから順序なしに変更するための設定 (前述)。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

この例は、​`diff`​ のさまざまな使用方法を示しています。

#### [](#ソース)ソース

```Dataweave
import diff from dw::util::Diff
ns ns0 http://locahost.com
ns ns1 http://acme.com
output application/dw
---
{
  "a": diff({a: 1}, {b:1}),
  "b": diff({ns0#a: 1}, {ns1#a:1}),
  "c": diff([1,2,3], []),
  "d": diff([], [1,2,3]),
  "e": diff([1,2,3], [1,2,3, 4]),
  "f": diff([{a: 1}], [{a: 2}]),
  "g": diff({a @(c: 2): 1}, {a @(c: 3): 1}),
  "h": diff(true, false),
  "i": diff(1, 2),
  "j": diff("test", "other test"),
  "k": diff({a: 1}, {a:1}),
  "l": diff({ns0#a: 1}, {ns0#a:1}),
  "m": diff([1,2,3], [1,2,3]),
  "n": diff([], []),
  "o": diff([{a: 1}], [{a: 1}]),
  "p": diff({a @(c: 2): 1}, {a @(c:2): 1}),
  "q": diff(true, true),
  "r": diff(1, 1),
  "s": diff("other test", "other test"),
  "t": diff({a:1 ,b: 2},{b: 2, a:1}, {unordered: true}),
  "u": [{format: "ssn",data: "ABC"}] diff [{ format: "ssn",data: "ABC"}]
}
```

#### [](#出力)出力

```XML
ns ns0 http://locahost.com
ns ns1 http://acme.com
---
{
  a: {
    matches: false,
    diffs: [
      {
        expected: "Entry (root).a with type Number",
        actual: "was not present in object.",
        path: "(root).a"
      }
    ]
  },
  b: {
    matches: false,
    diffs: [
      {
        expected: "Entry (root).ns0#a with type Number",
        actual: "was not present in object.",
        path: "(root).ns0#a"
      }
    ]
  },
  c: {
    matches: false,
    diffs: [
      {
        expected: "Array size is 0",
        actual: "was 3",
        path: "(root)"
      }
    ]
  },
  d: {
    matches: false,
    diffs: [
      {
        expected: "Array size is 3",
        actual: "was 0",
        path: "(root)"
      }
    ]
  },
  e: {
    matches: false,
    diffs: [
      {
        expected: "Array size is 4",
        actual: "was 3",
        path: "(root)"
      }
    ]
  },
  f: {
    matches: false,
    diffs: [
      {
        expected: "1" as String {mimeType: "application/dw"},
        actual: "2" as String {mimeType: "application/dw"},
        path: "(root)[0].a"
      }
    ]
  },
  g: {
    matches: false,
    diffs: [
      {
        expected: "3" as String {mimeType: "application/dw"},
        actual: "2" as String {mimeType: "application/dw"},
        path: "(root).a.@.c"
      }
    ]
  },
  h: {
    matches: false,
    diffs: [
      {
        expected: "false",
        actual: "true",
        path: "(root)"
      }
    ]
  },
  i: {
    matches: false,
    diffs: [
      {
        expected: "2",
        actual: "1",
        path: "(root)"
      }
    ]
  },
  j: {
    matches: false,
    diffs: [
      {
        expected: "\"other test\"",
        actual: "\"test\"",
        path: "(root)"
      }
    ]
  },
  k: {
    matches: true,
    diffs: []
  },
  l: {
    matches: true,
    diffs: []
  },
  m: {
    matches: true,
    diffs: []
  },
  n: {
    matches: true,
    diffs: []
  },
  o: {
    matches: true,
    diffs: []
  },
  p: {
    matches: true,
    diffs: []
  },
  q: {
    matches: true,
    diffs: []
  },
  r: {
    matches: true,
    diffs: []
  },
  s: {
    matches: true,
    diffs: []
  },
  t: {
    matches: true,
    diffs: []
  },
  u: {
    matches: true,
    diffs: []
  }
}
```