code: def test_metrics_diff_json(dvc, mocker, capsys):
      cli_args = parse_args(
          [
              "metrics",
              "diff",
              "HEAD~10",
              "HEAD~1",
              "--all",
              "--json",
              "--targets",
              "target1",
              "target2",
              "--no-path",
              "--precision",
              "10",
          ]
      )
  
      assert cli_args.func == CmdMetricsDiff
      cmd = cli_args.func(cli_args)
  
      diff = {"diff": {"metrics.yaml": {"": {"old": 1, "new": 3}}}}
      metrics_diff = mocker.patch(
          "dvc.repo.metrics.diff.diff", return_value=diff
      )
      show_diff_mock = mocker.patch("dvc.compare.show_diff")
  
      assert cmd.run() == 0
      out, _ = capsys.readouterr()
      metrics_diff.assert_called_once_with(
          cmd.repo,
          targets=["target1", "target2"],
          a_rev="HEAD~10",
          b_rev="HEAD~1",
          all=True,
      )
      show_diff_mock.assert_not_called()
      assert json.dumps(diff["diff"]) in out
  
imports: import json
  from dvc.cli import parse_args
  from dvc.commands.metrics import CmdMetricsDiff, CmdMetricsShow
label_desc: Use image node_id 2 for calling a global function with example usage: test_metrics_diff_json(dvc, mocker, capsys) without return types