


It could be any file that has a valid JSON format, such as a file containing information about products, customers, or weather data. The data.json file in the previous example is a file that contains data in JSON format. If the JSON file has a different structure, you may need to adjust the code accordingly. Please note that this code assumes that the JSON file is an array of objects, each having the same keys. The fieldnames for the writer are set to the keys of the first element of the data. Then, it creates a new CSV file and uses the CSV module’s DictWriter() class to write the data to the file.

In this example, the code first opens the JSON file using the open() function and the JSON module’s load() function, which reads the file’s contents and converts it to a Python object. # Create a new CSV file and write the data with open( 'data.csv', 'w', newline = '') as csv_file: I haven't tested this code as I don't have your csv-files but it gives a direction to dig.Import csv import json # Open the JSON file with open( 'data.json') as json_file: Path_2 = r"C:\Users\LordK\Desktop\Daten Krmnicek\Versuch JSON STruktur\MünzenID.csv"ĭf1 = pd.read_csv(path_1, names=FuFelder)ĭf2 = pd.read_csv(path_2, names=MüFelder) Path_json = r"C:\Users\LordK\Desktop\Daten Krmnicek\Versuch JSON STruktur\Skript\out.json" Path_1 = r"C:\Users\LordK\Desktop\Daten Krmnicek\Versuch JSON STruktur\FundorteID.csv" Your task could be accomplished in pandas much faster as it has built-in join function: import pandas as pd Move output.append(Fundrow)įor the future working with csv files I recommend using pandas library. You are updating output before you find necessary itemrow from MünzenReader. Right now i get the findplaces FuFelder displayed, but the nested list Fundrow ist still empty. Json.dump(output, jsonfile,sort_keys=True) MünzenReader = csv.DictReader( Münzen, fieldnames=MüFelder) MüFelder = įundorteReader = csv.DictReader( Fundorte, fieldnames=FuFelder) Münzen = open(r"C:\Users\LordK\Desktop\Daten Krmnicek\Versuch JSON STruktur\MünzenID.csv", 'r')įuFelder = Jsonfile = open(r"C:\Users\LordK\Desktop\Daten Krmnicek\Versuch JSON STruktur\Skript\out.json", 'w') The code used below: Fundorte = open(r"C:\Users\LordK\Desktop\Daten Krmnicek\Versuch JSON STruktur\FundorteID.csv", 'r') I want to create a JSON, so that i can implement geodata in the next step and create a nested GeoJason from this dataset.Īfterwards i wanted to use the Geodata in Leaflet. I wanted to create a nested structure, where every coind of a Findplace is linked inside a nested part of my findplace (Fundorte). I have two tables one containing Information over a findplace of archeological finds with a ID then i have a second table with many coins (80.000) linked with the ID to the findplaces. Problems joining two CSV Tables over ID and exporting as a nested JSON
