---
name: "Test2::Harness::Util::JSON"
section: "3pm"
platform: "linux"
package: "libtest2-harness-perl"
version: "1.000158-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Test2::Harness::Util::JSON"
---

# Test2::Harness::Util::JSON(3pm)

Utility class to help Test2::Harness pick the best JSON implementation.

## NAME

Test2::Harness::Util::JSON - Utility class to help Test2::Harness pick the best JSON implementation.

## DESCRIPTION

This package provides functions for encoding/decoding json, and uses the best json tools available.

## SYNOPSIS

```
    use Test2::Harness::Util::JSON qw/encode_json decode_json/;
    my $data = { foo => 1 };
    my $json = encode_json($data);
    my $copy = decode_json($json);
```

## EXPORTS

- $package = **JSON()**

  This returns the JSON package being used by yath.

- $bool = **JSON\_IS\_PP()**

  True if yath is using JSON::PP.

- $bool = **JSON\_IS\_XS()**

  True if yath is using JSON::XS.

- $bool = **JSON\_IS\_CPANEL()**

  True if yath is using Cpanel::JSON::XS.

- $bool = **JSON\_IS\_CPANEL\_OR\_XS()**

  True if either JSON::XS or Cpanel::JSON::XS are being used.

- $string = encode\_json($data)

  Encode data into json. String will be 1-line.

- $data = decode\_json($string)

  Decode json data from the string.

- $string = encode\_pretty\_json($data)

  Encode into human-friendly json.

- $string = encode\_canon\_json($data)

  Encode into canon-json.

## SOURCE

The source code repository for Test2-Harness can be found at *http://github.com/Test-More/Test2-Harness/*.

## MAINTAINERS

- Chad Granum \<exodist@cpan.org\>

  ## AUTHORS

- Chad Granum \<exodist@cpan.org\>

  ## COPYRIGHT

Copyright 2020 Chad Granum \<exodist7@gmail.com\>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See *http://dev.perl.org/licenses/*
