File size: 1,504 Bytes
8bea2b9 1fb58ab 8bea2b9 7ec77c2 8bea2b9 5fc02b5 7ec77c2 5fc02b5 8bea2b9 1fb58ab 8bea2b9 5fc02b5 1fb58ab 5fc02b5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<#
.SYNOPSIS
Formats JSON files from single-line to multi-line format using the jq command-line JSON processor.
.DESCRIPTION
The Format-JSONFiles function formats JSON files found in a specified directory using the jq command-line JSON processor.
It loops through each JSON file in the directory, applies jq formatting, and overwrites the original file with the formatted JSON.
.PARAMETER DirectoryPath
Specifies the directory path where the JSON files are located. Default value is "E:\yiff_toolkit\ponyxl_loras".
.EXAMPLE
Format-JSONFiles -DirectoryPath "C:\path\to\json_files"
Formats all JSON files in the "C:\path\to\json_files" directory.
.NOTES
Author: _ka_de
Date: 2024-04-20
Version: 1.0
#>
function Format-JSONFiles {
param (
[string]$DirectoryPath = "E:\yiff_toolkit\ponyxl_loras"
)
# Get a list of all JSON files in the specified directory
$jsonFiles = Get-ChildItem -Path $DirectoryPath -Filter "*.json"
# Loop through each JSON file and format it using jq
foreach ($file in $jsonFiles) {
# Construct the command to format the JSON file from single-line to multi-line
$command = "jq '.' '$($file.FullName)' > temp.json"
# Execute the command
Invoke-Expression -Command $command
# Overwrite the original file with the formatted content
Move-Item -Path "temp.json" -Destination $file.FullName -Force
Write-Host "Formatted $($file.Name) successfully."
}
}
|