Asking for a python code to show the structure from COD in a csv file

I am a beginner. and I can only got the json file that is hard to treat.
Can anyone offer me a python code to get structure in csv file?
It is really a hard work for me now.

I’m not sure a csv file will be any more useful – do you mean for just one structure or many? In either case Python has built-in support for JSON and CSV, so if that is really what you want the following code might get you started:

import json
import csv

with open("file.json") as f:
   data = json.load(f)

with open("file.csv", "w") as f:
    writer = csv.DictWriter(f, data.keys())
    writer.writeheader()
    writer.writerow(data)

If you run this with a JSON file containing the attributes of an OPTIMADE structure, e.g.,

{
  "immutable_id": "5f7731f0c99f02c3c002bef7",
  "last_modified": "2020-10-02T13:58:08.155000",
  "elements": [
    "Li"
  ],
  "nelements": 1,
  "elements_ratios": [
    1.0
  ],
  "chemical_formula_descriptive": "Li",
  "chemical_formula_reduced": "Li",
  "chemical_formula_hill": null,
  "chemical_formula_anonymous": "A",
  "dimension_types": [
    1,
    1,
    1
  ],
  "nperiodic_dimensions": 3,
  "lattice_vectors": [
    [
      7.7173642,
      -0.0049554,
      -0.0029381
    ],
    [
      7.1156988,
      2.9874011,
      -0.0029381
    ],
    [
      7.1156988,
      1.4307352,
      2.6225123
    ]
  ],
  "cartesian_site_positions": [
    [
      0.0,
      0.0,
      0.0
    ],
    [
      4.8765100504386,
      0.9805072928193,
      0.5813563587896999
    ],
    [
      17.0722517495614,
      3.4326736071807002,
      2.0352797412103003
    ]
  ],
  "nsites": 3,
  "species": [
    {
      "name": "Li",
      "chemical_symbols": [
        "Li"
      ],
      "concentration": [
        1.0
      ],
      "mass": null,
      "original_name": null,
      "attached": null,
      "nattached": null
    }
  ],
  "species_at_sites": [
    "Li",
    "Li",
    "Li"
  ],
  "assemblies": null,
  "structure_features": [],
  "_odbx_lattice_abc": [
    [
      7.717366350242964,
      7.717366349800575,
      7.717366350542895
    ],
    [
      22.81103208211113,
      22.811032116514056,
      22.811032268127235
    ]
  ],
  "_odbx_thermodynamics": {
    "enthalpy": -200.50472866666667,
    "total_energy": -200.4951059806667,
    "formation_energy": 0.0,
    "hull_distance": 0.0,
    "relative_enthalpy": null
  },
  "_odbx_dft_parameters": {
    "cut_off_energy": 800.0,
    "xc_functional": "PBE",
    "pseudopotentials": [
      {
        "identifier": "1|1.2|10|15|20|10U:20(qc=6)",
        "species": "Li",
        "pp_type": "ultrasoft",
        "raw": null,
        "scheme_desc": null,
        "library": null
      }
    ],
    "spin_treatment": "none",
    "external_pressure": null,
    "kpoint_spacing": 0.019,
    "geom_method": null,
    "geom_force_tol": 0.001
  },
  "_odbx_space_group": {
    "symbol": "R-3m",
    "spglib_tolerance": 0.001,
    "number": null
  },
  "_odbx_submitter": null,
  "_odbx_stress": 0.006,
  "_odbx_stress_tensor": null,
  "_odbx_forces": null,
  "_odbx_max_force_on_atom": 0.000574978260458602,
  "_odbx_tags": null,
  "_odbx_cell_volume": 60.619222004893125,
  "_odbx_fractional_site_positions": [
    [
      -0.0,
      -0.0,
      -0.0
    ],
    [
      0.222177,
      0.222177,
      0.222177
    ],
    [
      0.777823,
      0.777823,
      0.777823
    ]
  ],
  "_odbx_calculator": {
    "name": "CASTEP",
    "version_major": 17,
    "version_minor": 21.0,
    "commit_hash": "056e886bd5a1+",
    "architecture": "linux_x86_64_ifort17"
  },
  "_odbx_calculation_date": null
}

you will get back a csv file like:

immutable_id,last_modified,elements,nelements,elements_ratios,chemical_formula_descriptive,chemical_formula_reduced,chemical_formula_hill,chemical_formula_anonymous,dimension_types,nperiodic_dimensions,lattice_vectors,cartesian_site_positions,nsites,species,species_at_sites,assemblies,structure_features,_odbx_lattice_abc,_odbx_thermodynamics,_odbx_dft_parameters,_odbx_space_group,_odbx_submitter,_odbx_stress,_odbx_stress_tensor,_odbx_forces,_odbx_max_force_on_atom,_odbx_tags,_odbx_cell_volume,_odbx_fractional_site_positions,_odbx_calculator,_odbx_calculation_date
5f7731f0c99f02c3c002bef7,2020-10-02T13:58:08.155000,['Li'],1,[1.0],Li,Li,,A,"[1, 1, 1]",3,"[[7.7173642, -0.0049554, -0.0029381], [7.1156988, 2.9874011, -0.0029381], [7.1156988, 1.4307352, 2.6225123]]","[[0.0, 0.0, 0.0], [4.8765100504386, 0.9805072928193, 0.5813563587896999], [17.0722517495614, 3.4326736071807002, 2.0352797412103003]]",3,"[{'name': 'Li', 'chemical_symbols': ['Li'], 'concentration': [1.0], 'mass': None, 'original_name': None, 'attached': None, 'nattached': None}]","['Li', 'Li', 'Li']",,[],"[[7.717366350242964, 7.717366349800575, 7.717366350542895], [22.81103208211113, 22.811032116514056, 22.811032268127235]]","{'enthalpy': -200.50472866666667, 'total_energy': -200.4951059806667, 'formation_energy': 0.0, 'hull_distance': 0.0, 'relative_enthalpy': None}","{'cut_off_energy': 800.0, 'xc_functional': 'PBE', 'pseudopotentials': [{'identifier': '1|1.2|10|15|20|10U:20(qc=6)', 'species': 'Li', 'pp_type': 'ultrasoft', 'raw': None, 'scheme_desc': None, 'library': None}], 'spin_treatment': 'none', 'external_pressure': None, 'kpoint_spacing': 0.019, 'geom_method': None, 'geom_force_tol': 0.001}","{'symbol': 'R-3m', 'spglib_tolerance': 0.001, 'number': None}",,0.006,,,0.000574978260458602,,60.619222004893125,"[[-0.0, -0.0, -0.0], [0.222177, 0.222177, 0.222177], [0.777823, 0.777823, 0.777823]]","{'name': 'CASTEP', 'version_major': 17, 'version_minor': 21.0, 'commit_hash': '056e886bd5a1+', 'architecture': 'linux_x86_64_ifort17'}",

Note that array values do not place nicely with CSV (it is just encoding them as strings). Probably it would be better to learn how to deal with the JSON directly, or use tools that can convert OPTIMADE JSON structures into ASE Atoms or pymatgen structures (which can then be written to e.g., CIF files or otherwise).