NAME

File::SOPS::Format::JSON - JSON format handler for SOPS

VERSION

version 0.001

SYNOPSIS

use File::SOPS::Format::JSON;

# Parse JSON with SOPS metadata
my ($data, $metadata) = File::SOPS::Format::JSON->parse($json_content);

# Serialize data with SOPS metadata
my $json = File::SOPS::Format::JSON->serialize(
    data     => $encrypted_data,
    metadata => $metadata_obj,
);

# Check if filename is JSON
if (File::SOPS::Format::JSON->detect('secrets.json')) {
    # It's a JSON file
}

DESCRIPTION

JSON format handler for File::SOPS. Handles parsing and serialization of SOPS-encrypted JSON files.

Uses JSON::MaybeXS for JSON processing (automatically uses the fastest available JSON backend: Cpanel::JSON::XS, JSON::XS, or JSON::PP).

Output is always pretty-printed and canonically ordered for consistent diffs.

parse

my ($data, $metadata) = File::SOPS::Format::JSON->parse($json_string);

Class method to parse a JSON string.

Returns a two-element list:

1. $data - HashRef of the data (without the sops section)
2. $metadata - File::SOPS::Metadata object, or undef if no sops section

Dies if the JSON is invalid or doesn't parse to a HashRef.

serialize

my $json = File::SOPS::Format::JSON->serialize(
    data     => \%data,
    metadata => $metadata_obj,
);

Class method to serialize data and metadata to JSON.

The data parameter must be a HashRef. The metadata parameter must be a File::SOPS::Metadata object.

Returns a pretty-printed, canonically-ordered JSON string with the sops section included.

format_name

Returns 'json'.

file_extensions

Returns a list of file extensions: ('json').

detect

if (File::SOPS::Format::JSON->detect($filename)) {
    # File is JSON based on extension
}

Class method to detect if a filename is JSON based on extension.

Returns true if filename ends with .json (case-insensitive).

SEE ALSO

SUPPORT

IRC

You can reach Getty on irc.perl.org for questions and support.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <torsten@raudssus.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus.

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