This PR addresses an issue in the Bash script related to marzban status command. The original code was designed to extract the "Service" and "State" fields from JSON data. However, it was throwing an error when attempting to access these fields when the JSON input was not an array, resulting in a "Cannot index string with string" error.
To resolve this issue, the code has been refactored to handle both array and non-array JSON inputs gracefully. It now checks the type of JSON input and processes it accordingly:
If the JSON input is an array, it iterates through the elements and extracts the "Service" and "State" fields.
If the JSON input is not an array, it directly extracts the "Service" and "State" fields.
This modification ensures that the script works correctly with various JSON input formats, preventing errors and enhancing its overall robustness.
Changes Made
Refactored the JSON parsing logic to accommodate different JSON input formats.
Updated the services and states variables to handle both array and non-array JSON.
Utilized conditional logic to iterate through JSON elements only when it's an array.
Testing
Tested the updated script with various JSON inputs, including arrays and non-arrays, to ensure that it parses the "Service" and "State" fields correctly without errors.
Description
This PR addresses an issue in the Bash script related to
marzban status
command. The original code was designed to extract the "Service" and "State" fields from JSON data. However, it was throwing an error when attempting to access these fields when the JSON input was not an array, resulting in a "Cannot index string with string" error.To resolve this issue, the code has been refactored to handle both array and non-array JSON inputs gracefully. It now checks the type of JSON input and processes it accordingly:
This modification ensures that the script works correctly with various JSON input formats, preventing errors and enhancing its overall robustness.
Changes Made
services
andstates
variables to handle both array and non-array JSON.Testing
Tested the updated script with various JSON inputs, including arrays and non-arrays, to ensure that it parses the "Service" and "State" fields correctly without errors.
Related Issues
Fix: Gozargah/Marzban#549