How to parse JSON? (Advance)

JSON Structure: Pastebin

I’m working with OpenBullet 2 and trying to extract values from this JSON response.

I need to parse:

  • balance > balance > amount
  • crypto_balances > balance > amount

NameSpace

System.Text.Json

Code

BLOCK:ConstantString
  value = "{\"last_used_bonus_id\":null,\"last_used_bonus_uuid\":null,\"last_used_crypto_balance_id\":null,\"balance\":{\"balance\":{\"amount\":\"0.00\",\"currency\":\"EUR\"},\"wager\":{\"amount\":\"0.00\",\"currency\":\"EUR\"},\"total_deposit\":{\"amount\":\"0.00\",\"currency\":\"EUR\"},\"total_bet\":{\"amount\":\"0.00\",\"currency\":\"EUR\"},\"withdraw_limit\":{\"amount\":\"999999999\",\"currency\":\"EUR\"},\"real_total_profit\":{\"amount\":\"0.00\",\"currency\":\"EUR\"},\"total_payout\":{\"amount\":\"0.00\",\"currency\":\"EUR\"},\"current_payout\":{\"amount\":\"0.00\",\"currency\":\"EUR\"},\"in_game\":{\"amount\":\"0.00\",\"currency\":\"EUR\"},\"wager_percents\":100,\"payout_available\":{\"amount\":\"0.00\",\"currency\":\"EUR\"},\"total_created_payout\":{\"amount\":\"0.00\",\"currency\":\"EUR\"}},\"crypto_balances\":[{\"id\":null,\"balance\":{\"amount\":\"0.00000000\",\"currency\":\"USDT\"},\"wager\":{\"amount\":\"0.00000000\",\"currency\":\"USDT\"},\"total_deposit\":{\"amount\":\"0.00000000\",\"currency\":\"USDT\"},\"total_bet\":{\"amount\":\"0.00000000\",\"currency\":\"USDT\"},\"withdraw_limit\":{\"amount\":\"0.00000000\",\"currency\":\"USDT\"},\"real_total_profit\":{\"amount\":\"0.00000000\",\"currency\":\"USDT\"},\"total_payout\":{\"amount\":\"0.00000000\",\"currency\":\"USDT\"},\"current_payout\":{\"amount\":\"0.00000000\",\"currency\":\"USDT\"},\"in_game\":{\"amount\":\"0.00000000\",\"currency\":\"USDT\"},\"fiat_equivalent\":{\"amount\":{\"amount\":\"0\",\"currency\":\"EUR\"},\"currency\":\"EUR\"},\"wager_percents\":100,\"payout_available\":{\"amount\":\"0.00000000\",\"currency\":\"USDT\"},\"total_created_payout\":{\"amount\":\"0.00000000\",\"currency\":\"USDT\"}}],\"bonus_balances\":[],\"bonus_balances_EUR_amount\":0}"
  => VAR @json
ENDBLOCK
var doc = JsonDocument.Parse(json);
var root = doc.RootElement;

string balanceAmount = root
    .GetProperty("balance")
    .GetProperty("balance")
    .GetProperty("amount")
    .GetString();

string cryptoAmount = root
    .GetProperty("crypto_balances")[0]
    .GetProperty("balance")
    .GetProperty("amount")
    .GetString();

    MARK @balanceAmount

    MARK @cryptoAmount

1 Like

Has it been resolved? Exactly which part needs to be separated?

1 Like