---
name: "JSON::Validator::Util"
section: "3pm"
platform: "linux"
package: "libjson-validator-perl"
version: "5.15+dfsg-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/JSON::Validator::Util"
---

# JSON::Validator::Util(3pm)

Utility functions for JSON::Validator

## NAME

JSON::Validator::Util - Utility functions for JSON::Validator

## DESCRIPTION

JSON::Validator::Util is a package containing utility functions for JSON::Validator. Each of the "FUNCTIONS" can be imported.

## FUNCTIONS

### data\_checksum

```
  $str = data_checksum $any;
```

Will create a checksum for any data structure stored in `$any`.

### data\_section

```
  $str = data_section "Some::Module", "file.json";
  $str = data_section "Some::Module", "file.json", {encode => 'UTF-8'};
```

Same as "data\_section" in Mojo::Loader, but will also look up the file in any inherited class.

### data\_type

```
  $str = data_type $any;
  $str = data_type $any, [@schemas];
  $str = data_type $any, [{type => "integer", ...}];
```

Returns the JSON type for `$any`. `$str` can be array, boolean, integer, null, number object or string. Note that a list of schemas need to be provided to differentiate between "integer" and "number".

### is\_bool

```
  $bool = is_bool $any;
```

Checks if `$any` looks like a boolean.

### is\_num

```
  $bool = is_num $any;
```

Checks if `$any` looks like a number.

### is\_type

```
  $bool = is_type $any, $class;
  $bool = is_type $any, $type;
```

Checks if `$any` is a, or inherits from, `$class` or `$type`.

### negotiate\_content\_type

```
  $content_type = negotiate_content_type($header, \@content_types);
```

This method can take a "Content-Type" or "Accept" header and find the closest matching content type in `@content_types`. `@content_types` can contain wildcards, meaning "\*/\*" will match anything.

### prefix\_errors

```
  @errors = prefix_errors $prefix, @errors;
```

Consider this internal for now.

### schema\_type

```
  $str = schema_type $hash_ref;
  $str = schema_type $hash_ref, $any;
```

Looks at `$hash_ref` and tries to figure out what kind of type the schema represents. `$str` can be "array", "const", "number", "object", "string", or fallback to empty string if the correct type could not be figured out.

`$any` can be provided to double check the type, so if `$hash_ref` describes an "object", but `$any` is an array-ref, then `$str` will become an empty string. Example:

```
  # $str = "";
  $str = schema {additionalProperties => false}, [];
  # $str = "object"
  $str = schema {additionalProperties => false};
  $str = schema {additionalProperties => false}, {};
```

Note that this process is relatively slow, so it will make your validation faster if you specify "type". Both of the two below is valid, but the one with "type" will be faster.

```
  {"type": "object", "properties": {}} # Faster
  {"properties": {}}                   # Slower
```

### str2data

```
  $any = str2data $str;
```

Will try to parse `$str` as JSON or YAML, and return a data structure.

## SEE ALSO

JSON::Validator.
