dat2jsonβ Decode/restore Xray/Mihomogeoip.dat/geosite.datFiles to JSON/YAML source
dat2json is a high-performance CLI tool for decoding geoip.dat and geosite.dat files used by Xray, Mihomo (Clash Meta), and other V2Ray-based projects. It supports full or filtered export to JSON or YAML, with parallel processing, progress tracking, and multi-file output.
π Why use this?
Official.datfiles are binary and opaque. This tool lets you recover binary geolocation data files β without relying on closed-source generators.
- β
Decode both formats:
geoip.datβ country β CIDR lists (1.2.3.0/24)geosite.datβ tag β domain rules (domain:,full:,regexp:,keyword:)
- π Flexible output:
- Single file (
-o output.json) - One file per tag/country (
--output-dir ./export)
- Single file (
- π¦ Multiple formats: JSON, YAML (
.yamlor.yml) - π Filtering:
--tag=google,netflix(forgeosite.dat)--country=US,DE,CN(forgeoip.dat)
- π€ Sorting:
--sortfor deterministic, readable output - π Progress bar: Automatic for large files (>10k entries)
- β‘ Parallel export: Up to 32 concurrent writers for
--output-dir - π§© Universal compatibility: Works with:
- Official
.datfromv2fly/geoip - Official
.datfromv2fly/domain-list-community - Protobuf files from Mihomo runtime
- Official
- π‘οΈ Explicit mode selection: No ambiguity β you must specify
--ipor--site
- Go 1.23 or higher
- Git
git clone https://github.com/viktor45/dat2json.git
cd dat2json
go build -o dat2json .π‘ Add to
PATH:sudo mv dat2json /usr/local/bin/
# Convert geoip.dat to JSON (explicit --ip required)
./dat2json -i geoip.dat --ip -o countries.json
# Export only NL and RU to YAML
./dat2json -i geoip.dat --ip -o eu.yaml --country=NL,RU
# List all tags in geosite.dat
./dat2json -i geosite.dat --site --list-tags
# Export Netflix and Google to separate YAML files
./dat2json -i geosite.dat --site --output-dir ./rules --tag=netflix,google| Flag | Description | Required |
|---|---|---|
-i FILE |
Input .dat file |
β Yes |
--ip |
Treat input as geoip.dat (IP β CIDR) |
β
One of --ip or --site |
--site |
Treat input as geosite.dat (domains β rules) |
β
One of --ip or --site |
-o FILE |
Output file (.json, .yaml, or .yml) |
β (unless --output-dir or --list-tags) |
--output-dir DIR |
Export each tag/country to DIR/{name}.{ext} |
β |
--format FMT |
Force output format: json or yaml |
β |
--tag LIST |
Comma-separated tags (e.g., google,netflix) |
β ( --site only) |
--country LIST |
Comma-separated ISO 3166-1 alpha-2 codes (e.g., US,DE) |
β ( --ip only) |
--list-tags |
Print all tags in geosite.dat/geoip.dat and exit |
β ( --site only) |
--sort |
Sort keys alphabetically (countries/tags + domains/CIDRs) | β |
-h |
Show help | β |
β οΈ Notes:
- Use either
-oor--output-dirβ not both.- Country codes are case-insensitive (
us=US).- Tags are case-insensitive (
# See whatβs inside
./dat2json -i custom-geosite.dat --site --list-tags | grep -i "ad"
# Export ad-related tags
./dat2json -i custom-geosite.dat \
--site \
--output-dir ./ads \
--tag=category-ads,ads-all \
--sort./dat2json -i geoip.dat \
--ip \
-o eu-countries.yaml \
--country=DE,FR,IT,ES,NL,BE,AT,CH,SE,NO,DK,FI \
--sort./dat2json -i geoip.dat --ip --output-dir ./countries --format json
# β Creates ./countries/US.json, ./countries/CN.json, etc.# Mihomo's internal protobuf files have no header β use explicit mode
./dat2json -i mihomo-geoip.pb --ip -o countries.json
./dat2json -i mihomo-geosite.pb --site --output-dir ./rules| File | Signature | Content |
|---|---|---|
geoip.dat |
GEOI (optional) |
{ "US": ["1.2.3.0/24", ...], ... } |
geosite.dat |
GEOS (optional) |
{ "google": ["domain:.google.com", ...], ... } |
π‘ The tool does not rely on signatures β it uses the explicit
--ip/--siteflag to determine the parser.
- JSON: Standard indented JSON.
- YAML: Clean, human-readable YAML (uses
.yamlextension by default;.ymlaccepted on input).
- Parsing: Optimized for speed and memory efficiency.
- Export: Parallelized (up to 32 goroutines) when using
--output-dir. - Progress: Shown automatically for files with >10,000 entries.
Run unit tests:
go test ./...π Tests cover:
- Binary and protobuf parsing
- Format serialization
- Filtering and sorting
- Error handling
Contributions are welcome! Please:
- Fork the repo
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for details.
- V2Fly β for the original
.datformat and community datasets - Mihomo (Clash Meta) β for the protobuf schema and reference implementation
- YAML Spec β for standardizing
.yamlover.yml
π‘ Pro Tip: Combine with
v2fly/domain-list-communityandv2fly/geoipto rebuild.datfiles after modification!