Dump() Missing 1 Required Positional Argument: 'Fp' in Python Json

I am trying to prettify the json format but i am getting this error:

import requests as tt
from bs4 import BeautifulSoup
import json

get_url=tt.get("")
soup=BeautifulSoup(get_url.text,"html.parser")

select_css=soup.select("script#jsInit1")[0]
for i in select_css:
    print(json.dump(json.loads(i),indent=4,sort_keys=True))

Basically i want to extract this type of element :

'orig': {'width': 1080, 'url': '', 'height': 1349},

I know i can do this with

select_css.get('orig').get('url')

But i am not sure is this json element is nested element under any element ? That's why i am trying to prettify to get idea.

1

3 Answers

Use json.dumps() instead. json.dump() needs a file object and dump JSON to it.

It worked when I replaced

json_dump = json.dump(data_set)

by

json_dump = json.dumps(data_set)

You can use json.dumps() instead. json.dump() needs a file object and dump JSON to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest