Ich habe eine JSON-Datei mit diesen DatenWie entfernen Sie Null, falsche Werte aus der JSON-Datei?
{
"in_reply_to_screen_name": null,
"favorited": false,
"id_str": "92",
"entities": {
"user_mentions": [],
"symbols": [],
"urls": [],
"hashtags": [
{
"indices": [0,8]
}
]
},
"geo": null,
"user": {
"verified": false,
"notifications": null,
"profile_sidebar_border_color": "FFFFFF",
"geo_enabled": true,
"profile_background_tile": true,
"url": null,
"id": 278,
"default_profile": false,
"lang": "pt",
"location": null,
"translator_type": "none",
"protected": false
},
"id": 92,
"in_reply_to_status_id_str": null,
"in_reply_to_status_id": null,
"created_at": "Tue Oct",
"is_quote_status": false,
"text": "This is a vdd",
"truncated": false,
"retweeted": false
}
Wie kann ich alle Schlüssel-Wert-Paare löschen, die null, falsch und wahr diese Datei enthalten, mit Python?
Diese Werte können in verschiedenen Ebenen der Datenstruktur auftreten.
Was Sie bisher versucht haben? –
Neugierig, dass der Titel "Null, falsch" (d. H. "Falsy") Werte erwähnt, aber der Fragetext sagt "null, falsch ** und wahr **". Welches ist es? – alexis
@KevinJohnson, diese Schritte zum Beispiel: mit offenem (arq_geral, 'r') als f: für Zeile in f: tweet = json.loads (line) dados_tweet.append (tweet) für tweet in dados_tweet : wenn tweet ["geo"]: del tweet ["geo"] Es entfernt nicht zum Beispiel das 'geo'. –