Marvin
11/20/2024, 5:40 AMXmun
11/20/2024, 7:57 AMmichoel
11/20/2024, 9:13 AMMarvin
11/20/2024, 1:35 PMxml2json customsearch_mycustom_search_id.xml | jq ".definition" | awk -F'@' '{print $NF}' | base64 -d | gunzip | xml2json > customsearch_mycustom_search_id.json
Marvin
11/21/2024, 8:34 AM#!/usr/bin/env nix-shell
#! nix-shell -i bash
#! nix-shell -p bash gash-utils gzip jq libb64 python311Packages.xmljson
#! nix-shell -I nixpkgs=<https://github.com/NixOS/nixpkgs/archive/nixos-24.05.tar.gz>
# Validate input arguments
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <path-to-xml-file>"
exit 1
fi
input_file="$1"
# Validate the input file extension
if [[ "${input_file##*.}" != "xml" ]]; then
echo "Error: Input file must have a .xml extension."
exit 1
fi
# Check if the input file exists
if [ ! -f "$input_file" ]; then
echo "Error: File '$input_file' not found."
exit 1
fi
# Define the output file path
output_file="${input_file%.xml}.json"
# Convert XML to JSON
## Pull definition content
### Pull all content from after the @
#### used base64 to decode
##### un-gzip content which will result in XML
###### convert final XML into JSON
echo "Converting '$input_file' to '$output_file'..."
xml2json "$input_file" | jq ".definition" | awk -F'@' '{print $NF}' | base64 -i -d - | gunzip | xml2json > "$output_file" && echo "Conversion successful. JSON saved to '$output_file'." || echo "Error: Conversion failed."