0

For some reason, I am getting an error for something that has been working before can someone please tell me what is the problem.

    import os
    import json
    for filename in os.listdir(os.getcwd()):
        print(filename)
        if '.json' in filename:
            with open(filename, 'w') as y:
                filename = filename[:-5]
                json.dump({
                    "parent": "item/generated",
                    "textures": {
                        f"item/guildinterface/{filename}"
                    }

                }, y)


if __name__ == '__main__':
    main()

the error is

  File "C:/Heights/Documents/Projects/yotam/3.7/plutto/test.py", line 19, in <module>
    main()
  File "C:/Heights/Documents/Projects/yotam/3.7/plutto/test.py", line 15, in main
    }, y)
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py", line 179, in dump
    for chunk in iterable:
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python37-32\lib\json\encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python37-32\lib\json\encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python37-32\lib\json\encoder.py", line 438, in _iterencode
    o = _default(o)
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python37-32\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type set is not JSON serializable
SSharma
  • 951
  • 6
  • 15
yotam rec
  • 587
  • 4
  • 15
  • May be [this answer](https://stackoverflow.com/a/8230505/6699447) helps you. – Abdul Niyas P M Dec 06 '19 at 07:10
  • I didn`t understand anything from that article can you just tell me what do I need to change? – yotam rec Dec 06 '19 at 07:17
  • The error is pretty self-explanatory: you are trying to `json.dump` a `set`, which is the `{...}` after `"textures":`. There's no standard way to serialise a `set` to JSON. Use a list instead. – deceze Dec 06 '19 at 07:27

0 Answers0