'Flask SqlAlchemy: Returning None for JSON type inserts 'null' string, not real NULL

I'm using Flask SqlAlchemy. I'm inserting data into a Postgres DB and there is a JSON column type. When there is no data, I return None with the intention that that will set NULL into the column. This is what's suggested here.

if someCondition:
    json_obj = json.dumps(my_dict)
    return json_obj
else:
    return None # this inserts a 'null' string incorrectly
    # Only this works correctly:
    return null() # imported from sqlalchemy, 

But I see that this inserts a "null" string. The only way to get a real NULL is to use sqlalchemy.null(). Someone else noticed the same thing in this thread. Below is the difference from the two approaches. Can someone confirm that None should not be used for NULL insertion, to clear up the confusion?

enter image description here



Solution 1:[1]

What you describe is the default behavior.

The JSON and JSONB column type can be initialized with the parameter none_as_null set to True. This parameter is by default False.

The documentation for reference.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1