Query response to JSON format for Python v4

Hi,
Is there a way to convert QuerySearchReturnType object directly to json out of the box?

For query.near_text in python v3 we could directly do
print(json.dumps(response))
but for python v4, the returned object is not serializable

TypeError: Object of type QueryReturn is not JSON serializable

Example coode:

questions = client.collections.get("Question")
response = questions.query.near_text(
            query="biology",
            limit=2,
            return_properties=["category", "question", "answer"],
            return_metadata=MetadataQuery(distance=True)
        )
json.dumps(response) # this would fail

hi @darshit-s3 !!

Welcome to our community! :hugs:

This is a nice feature request.

A way of doing that, as of now, would be by introspecting each object and generating the json, or hard coding it from outside the client.

Please, feel free (and invited) to open an issue here:

So we can bring this to our developers.

Thanks!

we already have an issue for this Allow JSON-esque outputs through `str/repr` · Issue #881 · weaviate/weaviate-python-client · GitHub - but it is currently not planned

1 Like