Advertisement
metalx1000

URL Variable String to JSON

Jun 1st, 2025
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.39 KB | None | 0 0
  1. # The URL
  2. URL="https://example.com/path?param1=value1&param2=value2&param3=value%20with%20spaces"
  3.  
  4. # Cleanup/Decode URL Strings
  5. CLEAN_URL="$(busybox httpd -d "$URL")"
  6.  
  7. # Remove Domain
  8. QUERY_STRING=$(echo "$CLEAN_URL" | cut -d '?' -f 2)
  9.  
  10. # Vars as JSON
  11. echo "$QUERY_STRING"| jq -R 'split("&") | map(split("=") | {key: .[0], value: .[1]}) | reduce .[] as $item ( {}; .[$item.key] = $item.value )'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement