'I want to export a file as JSON but it gives an error

I want to get the outputs given in Terminal as a file. But I couldn't get it. It keeps giving error. How can I get these codes as files instead of terminal?

from youtubesearchpython import \*

'''
Searches for all types of results like videos, channels & playlists in YouTube.
'type' key in the JSON/Dictionary may be used to differentiate between the types of result.
'''
allSearch = Search('NoCopyrightSounds', limit = 1, language = 'en', region = 'US')
print(allSearch.result())

'''
Searches only for videos in YouTube.
'''
videosSearch = VideosSearch('NoCopyrightSounds', limit = 10, language = 'en', region = 'US')

print(videosSearch.result(mode = ResultMode.json))

''' '''`

import json

VideosSearch = {}

with open('data.txt', 'w') as outfile: json.dump(VideosSearch, outfile)

I tried this but it gave an error.

   json.dump(videosSearch, outfile)
  File "/opt/alt/python36/lib64/python3.6/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/opt/alt/python36/lib64/python3.6/json/encoder.py", line 437, in _iterencode
    o = _default(o)
  File "/opt/alt/python36/lib64/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'VideosSearch' is not JSON serializable


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source