When pulling a saved search object into SDF are we...
# sdf
m
When pulling a saved search object into SDF are we able to decode the definition into a readable definition?
x
gzip
m
Thanks for the article I was able to go to their repository and then convert it into bash commands. In case anybody wants to do that from bash I created this chain of commands that converts it to JSON.
Copy code
xml2json customsearch_mycustom_search_id.xml | jq ".definition" | awk -F'@' '{print $NF}' | base64 -d | gunzip | xml2json > customsearch_mycustom_search_id.json
thankyou 1
If you use Nix Shell this is a script that ensures all dependencies are there and then you just pass in path to the search xml and it will output a json file in the same directory.
Copy code
#!/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."