split_by_key: Split JSON Files Based on Unique Key Values

View source: R/split_by_key.R

split_by_keyR Documentation

Split JSON Files Based on Unique Key Values

Description

This function scans a source directory for JSON files, loads them, and splits each file into multiple smaller JSON files based on the unique values of a specified key. Each unique value results in a separate file.

Usage

split_by_key(input_dir, output_dir, split_key, data_path = NULL)

Arguments

input_dir

Character. Path to the directory containing source JSON files.

output_dir

Character. Path to the directory where split files will be saved.

split_key

Character. The name of the key/field used to isolate unique values (e.g., "Name of country" or "Sample matrix").

data_path

Character. If the JSON has a nested structure (like Norman API), provide the name of the element containing the list of records (e.g., "Data"). Defaults to NULL (assumes the JSON is a top-level list).

Details

The function creates the output directory if it does not exist. Filenames are generated using the pattern: original_name.json.

Value

Logical. Returns TRUE if the operation completes successfully.


normanR documentation built on Sept. 12, 2026, 5:10 p.m.