- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Reply to: Removing an array from a JSON file
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on "Removing an array from a JSON file"
Collapse
-
It looks like the original file is GeoJSON, so the geometry property is an object and a simple regex removing single lines isn't going to work.Originally posted by fulcon View PostMight be your edit but that's not valid JSON.
As you can't have line breaks in a property, you should be able to treat the 'geometry' line as a single line.
Because it's a large file, you don't want to read it all into memory in one go so this will do 5000 lines at a time:
Works on a little test file I made. YMMV.Code:$batchSize = 5000 Get-Content E:\bigFile.json -ReadCount $batchSize | Foreach-Object { $_ -replace "^\W*`"geometry`".+,$" | Where-Object { -not [String]::IsNullOrWhiteSpace($_) } | Add-Content E:\Temp\newFile.json }
Leave a comment:
-
Based on fulcon's regular expression.
Open the file up in Notepad++ and use the following search and replace
Replace the *, with *} if there isn't a , at the end of the geometry line but there should be.
Leave a comment:
-
As Eek will attest I am not a code monkey, what type of script is that? shell?Originally posted by fulcon View PostMight be your edit but that's not valid JSON.
As you can't have line breaks in a property, you should be able to treat the 'geometry' line as a single line.
Because it's a large file, you don't want to read it all into memory in one go so this will do 5000 lines at a time:
Works on a little test file I made. YMMV.Code:$batchSize = 5000 Get-Content E:\bigFile.json -ReadCount $batchSize | Foreach-Object { $_ -replace "^\W*`"geometry`".+,$" | Where-Object { -not [String]::IsNullOrWhiteSpace($_) } | Add-Content E:\Temp\newFile.json }
Leave a comment:
-
Might be your edit but that's not valid JSON.
As you can't have line breaks in a property, you should be able to treat the 'geometry' line as a single line.
Because it's a large file, you don't want to read it all into memory in one go so this will do 5000 lines at a time:
Works on a little test file I made. YMMV.Code:$batchSize = 5000 Get-Content E:\bigFile.json -ReadCount $batchSize | Foreach-Object { $_ -replace "^\W*`"geometry`".+,$" | Where-Object { -not [String]::IsNullOrWhiteSpace($_) } | Add-Content E:\Temp\newFile.json }
Leave a comment:
-
delete NameOfJsonObject.type.features.geometry would work but that only works if it's in memory.Originally posted by SimonMac View PostI have a huge JSON file (10m rows and still counting as it's not fully opened yet) however 99.9% is useless to me. There are about 2200 records in the following format
The problem is the geometry array (if that is the right term) is a list of co-ordinates with anything from 7 - 21 thousand lines that are useless to me, this means the overall file is 5gb+Code:{ "type" : "FeatureCollection", "name" : "%filename%", "features" : [ { "type" : "Feature", "geometry" : {=} "properties" : {=} }, { "type" : "Feature", "geometry" : {=} "properties" : {=} }, . . . ] }
At the moment I am going through each record and manaully deleting the array, is there a way to automate it? I don't want to spend an day going through all 2200 records just to be given a new version at some point meaning I will have to do it again.
Leave a comment:
-
Removing an array from a JSON file
I have a huge JSON file (10m rows and still counting as it's not fully opened yet) however 99.9% is useless to me. There are about 2200 records in the following format
The problem is the geometry array (if that is the right term) is a list of co-ordinates with anything from 7 - 21 thousand lines that are useless to me, this means the overall file is 5gb+Code:{ "type" : "FeatureCollection", "name" : "%filename%", "features" : [ { "type" : "Feature", "geometry" : {=} "properties" : {=} }, { "type" : "Feature", "geometry" : {=} "properties" : {=} }, . . . ] }
At the moment I am going through each record and manaully deleting the array, is there a way to automate it? I don't want to spend an day going through all 2200 records just to be given a new version at some point meaning I will have to do it again.Tags: None
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers
Contractor Services
CUK News
- Contractors, a £25million crackdown on rogue company directors is coming Today 05:02
- How to run a contractor limited company — efficiently. Part one: software Jan 22 23:31
- Forget February as an MSC contractor seeking clarity, and maybe forget fairness altogether Jan 22 19:57
- What contractors should take from Honest Payroll Ltd’s failure Jan 21 07:05
- HMRC tax avoidance list ‘proves promoters’ nothing-to-lose mentality’ Jan 20 09:17
- Digital ID won’t be required for Right To Work, but more compulsion looms Jan 19 07:41
- A remote IT contractor's allowable expenses: 10 must-claims in 2026 Jan 16 07:03
- New UK crypto rules now apply. Here’s how mandatory reporting affects contractors Jan 15 07:03
- What the Ray McCann Loan Charge Review means for contractors Jan 14 06:21
- IT contractor demand defied seasonal slump in December 2025 Jan 13 07:10

Leave a comment: