Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:10:47+00:00 2026-06-18T00:10:47+00:00

I am processing large text files using Python. Each line of a file is

  • 0

I am processing large text files using Python. Each line of a file is a complete JSON message, and might be very long. I need to insert information about each line into a database. This info is very simple: the length of the line plus a unique ID which each message contains. So each line has the form

{"field1":"val1", ..., "ID":"12345", ..., "fieldK":"valK"}

and I need to extract “12345” from the message.

Right now I load the entire string using json.loads() then find the ID and ignore the rest.

My code is too slow and I need to speed it up. I am trying to see if there is a way of extracting “ID” faster than loading like the whole string. One option is to search the string for “ID” and then process :"12345". But it might be brittle if it so happens that there is a substring “ID” someplace else in the message.

So is there a way of somehow partially loading the line to find ID, which would be as robust as, but also faster than, loading the whole line?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:10:48+00:00Added an answer on June 18, 2026 at 12:10 am

    I would recommend a couple of paths:

    If your input is very large, it may be that loading it wholly into memory is wasteful. It may be faster to load/parse each line separately.

    If the above won’t help, then devising some way to search for the right ID in the file isn’t a bad idea. Just verify that the input is kosher when you actually find the right ID: number. So you should:

    1. Search (regex or otherwise) for the ID you expect.
    2. For a match, actually parse the line and make sure it’s valid. If it isn’t (say, just ID: embedded in some string), drop it and keep searching.

    Since non-legit occurrences of (2) should be rare, the verification doesn’t have to be very efficient.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am processing large text files (~20MB) containing data delimited by line. Most data
I'm doing some processing on some very large video files (often up to 16MP),
I have quite a long script which involves chopping lots of large text files
When trying to do data processing on large delimited text files I decided to
I often need to process large text files containing headers in the first line.
I have to deal with very large text files (2 GBs), it is mandatory
I'm processing a large amount of : splitted data with Python. And I'm having
I have a program to process very large files. Now I need to show
I need to display large-ish text files (under 10 MB) on mobile device browsers.
I'm working on a Pig script (my first) that loads a large text file.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.