Python Forum
geojson to json --missing multiple row output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
geojson to json --missing multiple row output
#3
I would take thought Pandas first with use json_normalize(),then use df.to_csv(index=False).
import pandas as pd
from pprint import pprint
import json

with open('zz.json') as f:
    data = json.loads(f.read())

#df = pd.read_json('attachment.json', orient='index')
df = pd.json_normalize(data, record_path=['features'])
pprint(df)

html_out = df.to_html(index=False)
       type  ...                       geometry.coordinates
0   Feature  ...   [-168.93819999971066, 53.75961000002098]
1   Feature  ...  [-156.47280000002033, 20.898610000380238]
2   Feature  ...  [-146.34639999974192, 61.124730000130796]
3   Feature  ...   [-164.53890000013152, 67.71917999998502]
4   Feature  ...  [-117.17840000026474, 32.708209999763774]
5   Feature  ...   [-122.21401199961349, 37.50536000026958]
.... ect
So it want dispaly all,could fix this but i also save to Html.
There is also Foundation import that you don't see so then the table look better.
Html output of zz.json Features

print(df.to_csv(index=False))
Output:
type,properties.OBJECTID_1,properties.OBJECTID,properties.ID,properties.PORT,properties.PORT_NAME,properties.GRAND_TOTA,properties.FOREIGN_TO,properties.IMPORTS,properties.EXPORTS,properties.DOMESTIC,geometry.type,geometry.coordinates Feature,1,1,124,C4947,"Unalaska Island, AK",1652281,1236829,426251,810578,415452,Point,"[-168.93819999971066, 53.75961000002098]" Feature,2,2,85,C4410,"Kahului, Maui, HI",3615449,20391,20391,0,3595058,Point,"[-156.47280000002033, 20.898610000380238]" Feature,10,10,27,C4816,"Valdez, AK",25807750,249648,0,249648,25558102,Point,"[-146.34639999974192, 61.124730000130796]" Feature,11,11,130,C4978,"Kivilina, AK",1359589,3367,3367,0,1356222,Point,"[-164.53890000013152, 67.71917999998502]" .... ect
Reply


Messages In This Thread
RE: geojson to json --missing multiple row output - by snippsat - Mar-05-2022, 11:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to generating multiple json files using python script dzgn989 4 430 May-10-2024, 03:09 PM
Last Post: deanhystad
  Parse JSON multiple objects larkin_L 8 6,130 May-27-2020, 11:18 AM
Last Post: nuffink
  json.dumps list output qurr 12 5,564 Apr-08-2020, 10:13 PM
Last Post: micseydel
  API JSON response missing list gives keyerror rolfmadsen 3 3,666 Mar-28-2020, 10:12 AM
Last Post: buran
  print python json dump onto multiple lines lhailey 2 20,365 Mar-02-2020, 12:47 PM
Last Post: vishalhule
  json.dumps output error in python3 prayuktibid 2 2,806 Jan-21-2020, 06:41 AM
Last Post: prayuktibid
  Output to a json file problem Netcode 3 3,919 Nov-22-2019, 01:44 AM
Last Post: Skaperen
  Multiprocessing.Queue Issues (Missing/Corrupted Items/No Output) python3noob 0 3,325 Aug-03-2019, 09:38 PM
Last Post: python3noob
  Using the GeoJSON API ashlynjane 1 4,844 May-27-2019, 04:54 PM
Last Post: heiner55
  decoding sub.process output with multiple \n? searching1 2 2,924 Feb-24-2019, 12:00 AM
Last Post: searching1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020