Skip to content

Instantly share code, notes, and snippets.

@zjx20
Last active April 1, 2026 08:57
Show Gist options
  • Select an option

  • Save zjx20/25dff5a670ca55d8aba223f508691dfb to your computer and use it in GitHub Desktop.

Select an option

Save zjx20/25dff5a670ca55d8aba223f508691dfb to your computer and use it in GitHub Desktop.
Convert v2ray config.json (client side) to a subscription content
#!/bin/bash
# brew install jq
# brew install qrencode
config_file=v2rayx*.json
rss_file=rss.txt
cat $config_file | \
jq --raw-output '
def cred:
"\(.settings.vnext[0].users[0].security):\(.settings.vnext[0].users[0].id)@\(.settings.vnext[0].address):\(.settings.vnext[0].port)"
;
def header_host:
(.streamSettings.wsSettings.headers // {}) as $h |
($h | to_entries | map(select(.key|ascii_downcase == "host")) | .[0]?.value)
;
def network:
if .streamSettings.network == "ws" then
("path=\(.streamSettings.wsSettings.path)&obfs=websocket"
+ (header_host as $host | if $host then "&obfsParam=\($host)" else "" end))
else
"obfs=none"
end
;
def tls:
if .streamSettings.security == "tls" then
"tls=1&peer=\(.streamSettings.tlsSettings.serverName)"
else
"tls=0"
end
;
def mux:
if .mux?.enabled? then "mux=1" else "mux=0" end
;
def alterid:
"\(.settings.vnext[0].users[0].alterId)"
;
.outbounds | map(select(.protocol == "vmess")) | .[] |
cred as $cred |
network as $network |
tls as $tls |
mux as $mux |
alterid as $alterid |
{ cred: $cred, remarks: .tag, network: $network, tls: $tls, mux: $mux, alterid: $alterid } |
.cred = @base64 "\(.cred)" | .remarks = @uri "\(.remarks)" |
"vmess://\(.cred)?remarks=\(.remarks)&\(.network)&\(.tls)&\(.mux)&alterId=\(.alterid)"' | \
base64 > $rss_file
# put $rss_file to somewhere, then your qr code for the subscribe link is
rss_url="https://yourserver/rss.txt"
qrencode -t ANSI $(echo "sub://$(echo "$rss_url" | base64)")
@mulezic

mulezic commented Feb 6, 2024

Copy link
Copy Markdown

@zjx20
I would also love to know how to convert a JSON file to a URL, but the English of "base64 decode output file" is just way too much for me, I'm not an IT guy.

@zjx20

zjx20 commented Feb 6, 2024

Copy link
Copy Markdown
Author

@mulezic Sorry, I can't help you if you are not familiar with this IT stuff (e.g. shell scripts, base64 encoding, etc.). Maybe you can say more about what you're trying to do, and maybe it can be solved in a different way.

@mulezic

mulezic commented Feb 6, 2024 via email

Copy link
Copy Markdown

@zjx20

zjx20 commented Feb 7, 2024

Copy link
Copy Markdown
Author

@mulezic OK, I understand. You can tell me what server software or script you are using, what client you are planning to use, and also a sample json config (without sensitive information). I can help you determine the feasibility of the situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment