Registry / web-framework / wtforms-json

wtforms-json

JSON →
library0.3.5pypypi✓ verified 84d ago

WTForms-JSON extends WTForms to provide convenient serialization and deserialization of form data to and from JSON, particularly useful for RESTful APIs. It allows forms to be populated directly from JSON payloads and validates them as usual. The latest version is 0.3.5, released in 2017. The project appears to be unmaintained.

pip install wtforms-json
INSTALL
IMPORT
SIG · WTFORMS-JSON
W
wtforms-json
web-frameworkpythonv0.3.5
Install
2.6s avg
Import
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 20.5MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.6s · import 0.000s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

init
from wtforms_json import init
from wtforms_json import init_app

Demonstrates initializing wtforms-json and populating a form with JSON data, followed by validation. It shows handling both valid and invalid JSON inputs.

from wtforms import Form, StringField, IntegerField from wtforms.validators import DataRequired, NumberRange from wtforms_json import init_app # Initialize wtforms-json to extend WTForms functionality init_app() class UserProfileForm(Form): name = StringField('Name', validators=[DataRequired()]) age = IntegerField('Age', validators=[NumberRange(min=0, max=120)]) # Example JSON data (e.g., from a request body) valid_json_data = {'name': 'Jane Doe', 'age': 25} invalid_json_data = {'name': '', 'age': 150} # Name missing, age out of range print("--- Processing valid data ---") form_valid = UserProfileForm() form_valid.from_json(valid_json_data) # Populate form from JSON if form_valid.validate(): print(f"Form is valid. Data: {form_valid.data}") else: print(f"Form errors: {form_valid.errors}") print("\n--- Processing invalid data ---") form_invalid = UserProfileForm() form_invalid.from_json(invalid_json_data) if form_invalid.validate(): print(f"Form is valid. Data: {form_invalid.data}") else: print(f"Form errors: {form_invalid.errors}")
Debug
Known issues
breakingWTForms-JSON has not been updated since 2017 and was last tested with WTForms 2.1. It is highly likely to have compatibility issues with modern WTForms 3.x+ and newer Python versions (3.8+).
fix
For new projects, consider modern alternatives or manually handle JSON serialization/deserialization. If migrating, thoroughly test with your specific WTForms and Python versions.
affects: <=0.3.5
gotchaThe project is unmaintained. No new features, bug fixes, or security patches are expected. Relying on this library for new development is not recommended.
fix
Evaluate actively maintained alternatives for JSON handling with WTForms or implement custom solutions.
affects: <=0.3.5
gotchaTo enable JSON processing for all WTForms forms, `wtforms_json.init_app()` must be called once at the start of your application. Failing to do so will mean forms do not gain the `.from_json()` method.
fix
Ensure `init_app()` is called early in your application's lifecycle, typically during setup or configuration.
affects: <=0.3.5
gotchaError messages and validation behavior for JSON input might be less configurable or user-friendly compared to contemporary libraries or custom implementations.
fix
Be prepared to implement custom error formatting or validation logic around WTForms-JSON if specific error structures are required for your API.
affects: <=0.3.5
Upgrade
Version history
0.3.5latest on PyPI · released Apr 16, 2022
Audit
Dependencies
WTFormsrequiredCore dependency for form definition and validation.
Agent activity
16 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
wtforms-json — pip install wtforms-json · libregistry