0

Consider the following json dict:

print(new_table)

{
    "Name": "areas_json",
    "Parameters": {
        "CrawlerSchemaDeserializerVersion": "1.0",
        "CrawlerSchemaSerializerVersion": "1.0",
        "UPDATED_BY_CRAWLER": "crawler",
        "averageRecordSize": "100",
    }
}

I'm trying to add (append) another line to Parameters at the top.

I've attempted this with the following code:

new_table["Parameters"].append({"new_row":"example"})

I get the error: 'dict' object has no attribute 'append'

What is the right way to append to a python dictionary?

Desired output:

print(new_table)

{
    "Name": "areas_json",
    "Parameters": {
        "new_row":"example",
        "CrawlerSchemaDeserializerVersion": "1.0",
        "CrawlerSchemaSerializerVersion": "1.0",
        "UPDATED_BY_CRAWLER": "crawler",
        "averageRecordSize": "100",
    }
}
ire
  • 491
  • 2
  • 12
  • 26

1 Answers1

1

You need update instead of append as:

t['Parameters'].update({"new_row":'example'})

append is for the list object.

Krishna Chaurasia
  • 8,924
  • 6
  • 22
  • 35