
How to use JSON fields in Odoo.
JSON fields allow you to store structured and flexible data inside a single field. They are useful when data does not have a fixed schema or changes frequently.
✅ JSON Field Definition
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
extra_info = fields.Json(string="Extra Information")
Storing Data in JSON Field
product.extra_info = {
'color': 'Red',
'weight': 10,
'is_fragile': True
}
reading JSON Data
color = product.extra_info.get('color')
✅ Use Cases
API response storage
Dynamic product attributes
Configuration values
✅ Best Practice:
Use JSON fields only when relational fields are not suitable. JSON data is harder to search and index.