"""Serializes a DAG into a JSON object."""
        try:
            serialized_dag = cls.serialize_to_json(dag, cls._decorated_fields)
            serialized_dag["_processor_dags_folder"] = DAGS_FOLDER
            
            
            if dag.timetable.summary == dag.schedule_interval:
                del serialized_dag["schedule_interval"]
            else:
                del serialized_dag["timetable"]
            serialized_dag["tasks"] = [cls.serialize(task) for _, task in dag.task_dict.items()]
            dag_deps = {
                dep
                for task in dag.task_dict.values()
                for dep in SerializedBaseOperator.detect_dependencies(task)
            }
            dag_deps.update(DependencyDetector.detect_dag_dependencies(dag))
            serialized_dag["dag_dependencies"] = [x.__dict__ for x in dag_deps]
            serialized_dag["_task_group"] = TaskGroupSerialization.serialize_task_group(dag.task_group)