{
  "id": 1558351,
  "title": "Parsing numbers from JSON in Python",
  "url": "https://urgent.news/2026/08/17/parsing-numbers-from-json-in-python",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-17T20:25:39.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/pomidoroshev/parsing-numbers-from-json-in-python-2e8c"
  },
  "original_language": "en",
  "account": "In a Python-based web server, the withdraw.py script is used to withdraw a requested amount from a user's balance. The script uses the json module to parse incoming JSON data and the Flask framework for handling HTTP requests. The STATE dictionary is employed to maintain the user's balance for simplification purposes.\n\nThe script starts by importing necessary modules and initializing the Flask app and the STATE dictionary with an initial balance of 1000. A POST request is defined for the /withdraw endpoint, which attempts to withdraw the requested amount from the user's balance. The script checks for three conditions: validity of the JSON input, amount type, and whether the amount is within acceptable limits.\n\nTesting the JSON input validation reveals that the script accepts various numeric values and even the non-standard JSON constant NaN. However, passing NaN leads to unexpected consequences - the balance is replaced with float('nan'), and subsequent withdrawals continue without issue. This issue persists across different databases like SQLite and PostgreSQL, causing further complications as SQLite converts NaN to NULL, while PostgreSQL can store NaN as a numeric value, corrupting the balance differently.",
  "summary": "Consider this hypothetical endpoint in a Python-based web-server: # withdraw.py import json from flask import Flask , request app = Flask ( __name__ ) STATE = { \" balance \" : 1000 } @app.post ( \" /withdraw \" ) def withdraw (): \"\"\" Withdraw a requested amount from the user ' s balance \"\"\" try : data = json . loads ( request . data ) except ValueError : return \" Malformed JSON \" , 400 if not…",
  "key_points": [
    "Python script withdraw.py uses json module to parse incoming JSON data",
    "STATE dictionary maintains user's balance for simplification",
    "JSON input validation allows numeric values, including NaN, causing balance issues"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}