Python Forum
Indirectlty convert string to float in JSON file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Indirectlty convert string to float in JSON file
#3
Hi, thank you for clues, it helped me,

the code below worked:

with open(filepath, 'r+', encoding='utf-8') as data_jason:

 data = json.load(data_jason)

 
 for feature in data['features']:
     print (feature['geometry']['coordinates'][0])
     splitted = feature['geometry']['coordinates'][0].split(',')
     print(splitted)
     floated = [float(i) for i in splitted]
     print(floated)
     del feature['geometry']['coordinates']
     feature['geometry']['coordinates'] = []
     feature['geometry']['coordinates'].extend(floated)
     print(feature['geometry']['coordinates'])

 json.dump(data, data_jason,  indent=4)
Dumping write at the end of the file how could I make it overwrite it instead ?
Reply


Messages In This Thread
RE: Indirectlty convert string to float in JSON file - by WBPYTHON - May-06-2020, 11:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Parse Nested JSON String in Python rwalde 4 3,066 Sep-08-2022, 10:32 AM
Last Post: rwalde
Sad ValueError: could not convert string to float badju 0 4,366 Jul-01-2021, 12:13 AM
Last Post: badju
  HELP! Importing json file into csv into jupyter notebook vilsef 2 2,623 Jan-22-2021, 11:06 AM
Last Post: snippsat
  JSON file Loading issue punna111 4 8,699 Jun-29-2020, 08:07 AM
Last Post: buran
  ValueError: could not convert string to float RahulSingh 3 4,291 Apr-09-2020, 02:59 PM
Last Post: dinesh
  convert a list of string+bytes into a list of strings (python 3) pacscaloupsu 4 10,954 Mar-17-2020, 07:21 AM
Last Post: markfilan
  Help batch converting .json chosen file to MySQL BrandonKastning 2 2,390 Mar-14-2020, 09:19 PM
Last Post: BrandonKastning
  Convert dataframe string column to numeric in Python darpInd 1 2,336 Mar-14-2020, 10:07 AM
Last Post: ndc85430
  convert 'A B C' to numpy float matrix rezabma 4 2,606 Feb-27-2020, 09:48 AM
Last Post: rezabma
  ValueError: could not convert string to float: '4 AVENUE' Kudzo 4 6,015 Jan-26-2020, 10:47 PM
Last Post: Kudzo

Forum Jump:

User Panel Messages

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