JSON To CSV using Python

Поделиться
HTML-код
  • Опубликовано: 9 мар 2022
  • In this video we will convert a JSON object to CSV using python. The code for this video is located in the GitHub repo:
    github.com/bugandcode-io/PYTH...

Комментарии • 11

  • @xx-jl3gl
    @xx-jl3gl Год назад

    Thank you! It works perfectly

  • @AshishKumar-us2nd
    @AshishKumar-us2nd Год назад

    Thanks! Great help

  • @iam9_39
    @iam9_39 3 месяца назад

    ❤❤❤ thanks a lot

  • @sujitreddy7702
    @sujitreddy7702 Год назад

    Hey how can I contact you? I need some help with modifying this use case a bit.

  • @abisandy1481
    @abisandy1481 9 месяцев назад

    My json file structure is
    [
    {
    "attributes":{
    "Phone" : [
    {
    "Label": "abcd"
    "Value":{
    " Type":[
    {
    "Type": " Xyz"
    }
    ]
    In this structure, how could i read key values?

  • @akbarxojaabduraximov7427
    @akbarxojaabduraximov7427 Год назад

    Hello,
    I had a problem, I wrote a script according to your instructions and as a result I get only columns, and the data in these columns is not exported

  • @akbarxojaabduraximov7427
    @akbarxojaabduraximov7427 Год назад +2

    import json
    def export_to_csv():
    with open("D:/Scripting/ToShPfile.json") as f:
    list1 = []
    ToShPfile = json.loads(f.read())
    temp = ToShPfile[0]
    header_items = []
    get_header_items(header_items, temp)
    list1.append(header_items)

    for obj in ToShPfile:
    d = []
    add_items_to_ToShPfile(d, obj)
    list1.append(d)

    with open ('output.csv', 'w') as output_file:
    for a in list1:
    output_file.write(','.join(map(str, a)) + "
    ")

    def get_header_items(items, obj):
    for x in obj:
    if isinstance(obj[x], dict):
    items.append(x)
    get_header_items(items, obj[x])
    else:
    items.append(x)
    def add_items_to_ToShPfile(items, obj):
    for x in obj:
    if isinstance(obj[x], dict):
    items.append("")
    get_header_items(items, obj[x])
    else:
    items.append(obj[x])

    export_to_csv()

    • @soulmusic9274
      @soulmusic9274 9 месяцев назад

      in def add_items_to_ToShPfile change get_header_items to add_items_to_ToShPfile

  • @user-tx2qe9qz4b
    @user-tx2qe9qz4b Год назад

    not able to see csv in table form

  • @marcosd3976
    @marcosd3976 10 месяцев назад

    key typiyng is anoying