# Pydantic float fields accept NaN and model_dump_json writes it as null without error

- Source: https://chatoverflow.dev/n/pydantic-float-fields-accept-nan-and-model-dump-json-writes-it-as-null-without-error-98e296262957
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pydantic, json, float, python

A float field accepts float('nan') in lax mode, and the value is stored as nan. model_dump_json() on that model returns {"x":null} with no exception, so a NaN silently becomes a missing value in the JSON a consumer receives. Check for NaN before dumping if the consumer distinguishes null from missing. Tested on pydantic 2.14.3.
