Skip to content

Feat/improve json output#853

Draft
thewhaleking wants to merge 11 commits intostagingfrom
feat/improve-json-output
Draft

Feat/improve json output#853
thewhaleking wants to merge 11 commits intostagingfrom
feat/improve-json-output

Conversation

@thewhaleking
Copy link
Contributor

Building upon #781

DanielDerefaka and others added 9 commits December 22, 2025 17:12
This PR introduces a centralized json_utils module to standardize JSON output
across all btcli commands, addressing the inconsistencies noted in issue #635.

Changes:
- Add `bittensor_cli/src/bittensor/json_utils.py` with standardized helpers:
  - `json_response()` - Base response formatter
  - `json_success()` - Success response helper
  - `json_error()` - Error response helper
  - `json_transaction()` - Transaction response helper
  - `serialize_balance()` - Consistent Balance serialization

- Update `wallets.py` with sample usage (3 functions updated as POC)

- Add comprehensive unit tests (21 tests) for schema compliance

Standard Response Format:
```json
{
    "success": bool,
    "data": {...},     // Optional: command-specific data
    "error": str       // Optional: error message
}
```

This establishes the foundation for full migration of all commands to use
consistent JSON schemas. Additional commands can be migrated incrementally.

Closes #635
…identifier

- Add TransactionResult and MultiTransactionResult classes for consistent
  transaction responses across all commands
- Add print_transaction_response() helper function
- Update schema to use {success, message, extrinsic_identifier} format
- Migrate wallets.py: transfer, swap_hotkey, set_id
- Migrate sudo.py: trim command
- Migrate stake/add.py and stake/remove.py
- Migrate liquidity.py: add_liquidity, remove_liquidity, modify_liquidity
- Update tests for new transaction response utilities (25 tests passing)

This addresses feedback from @thewhaleking on PR #781 to apply standardized
JSON output to all json_console usages with extrinsic_identifier support.

Closes #635
Complete migration of 169 json_console usages across 22 files to use
the standardized print_json_data, print_transaction_response, and
print_transaction_with_data utilities from json_utils.py.

Files migrated:
- crowd/*.py (6 files)
- subnets/*.py (3 files)
- stake/*.py (6 files)
- wallets.py
- sudo.py
- proxy.py
- liquidity/liquidity.py
- axon/axon.py
- weights.py
- json_utils.py (added print_transaction_with_data helper)
Resolved conflicts in:
- stake/auto_staking.py: Keep print_success, remove json_console (migrated)
- wallets.py: Remove both err_console and json_console (unused after migration)
Migrated one more json_console.print_json call in proxy.py that came
from upstream merge to use print_transaction_response instead.
# Conflicts:
#	bittensor_cli/src/commands/crowd/view.py
#	bittensor_cli/src/commands/stake/auto_staking.py
#	bittensor_cli/src/commands/wallets.py
…` arg to print_error and print_success for future consolidation
@thewhaleking thewhaleking linked an issue Mar 13, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve JSON output

2 participants