Comments (5)
Just to add a bit more detail, iter_lines() seems to give the entire stream as a binary string since the JSON is not formatted with newline characters. iter_content() gives the data in a stream format returning what looks like 1 or 2 binary characters at a time.
I thought ijson was able to handle a stream. Surely that stream doesn't need to be formatted?
from ijson.
@raeldor my previous advice was to build something around iter_content
, not to pass it (or iter_lines
) directly with ijson. As mentioned before, ijson works with file-like objects; that is, objects with a read
method, so you'd need to wrap the response to make it look like a file that can be read.
Something like this:
import ijson
import requests
class ResponseAsFileObject:
def __init__(self, url):
response = requests.get(url, stream=True)
self.data = response.iter_content(chunk_size=65536)
def read(self, n):
if n == 0:
return b''
return next(self.data, b'')
URL = 'your-url'
for prefix, event, name in ijson.parse(ResponseAsFileObject(URL)):
print(prefix, event, name)
from ijson.
@raeldor please let me know if this worked so we can close this.
from ijson.
There hasn't been a response in a week, and the solution worked for me, so I'm closing this.
from ijson.
from ijson.
Related Issues (20)
- YAJL backend not working in Win/Conda HOT 3
- Segmentation fault with yajl2 backend HOT 3
- How to define a prefix where an object contains dot characters HOT 2
- Generators created by ijson.items() do not seem to have an end HOT 5
- Nested structure reading HOT 2
- Use stacklevel to point str vs bytes warning to user code HOT 3
- Release wheels for 3.11 HOT 6
- How to determine which backend is being used at runtime? HOT 3
- Is the yajl_c backend supported on PyPy? HOT 7
- High level interface to iterate over lists HOT 3
- HighLevelAPI: Raise an error if the prefix does not exist HOT 2
- Is it possible to use multiple prefix HOT 8
- yajl2_c backend for lambda function HOT 2
- How to use ijson to covert string to dict? HOT 3
- How to read json records in chunks using ijson? HOT 4
- Question: is it possible that returing bytes instead of str could speedup parsing? HOT 3
- Thread safety HOT 9
- Full support for byte stream generator HOT 9
- Allow to use ijson package by a relative import HOT 4
- How can I most-efficiently check for a key in the top-level of a json object? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ijson.