split_by_pattern: Split JSON Files Based on Partial Key Values (Pattern...

View source: R/split_by_pattern.R

split_by_patternR Documentation

Split JSON Files Based on Partial Key Values (Pattern Matching)

Description

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

Usage

split_by_pattern(
  input_dir,
  output_dir,
  split_key,
  pattern = NULL,
  data_path = NULL
)

Arguments

input_dir

Character. Path to the folder containing source JSON files.

output_dir

Character. Path to the folder where output files will be saved.

split_key

Character. The JSON key to inspect (e.g., "Sampling date").

pattern

Character (Regex). A pattern to extract. If NULL, splits by full value.

data_path

Character. The element in the JSON containing the records 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.