How to create Dict from Collection Property in Blender python? I want to get a dict from a collection property which will be used for exporting a json file.
I completely have no idea how I should do it, so I don't have any code for it.
Thanks for helping me.
I have a propertyGroup-
class Favourites(PropertyGroup):
    label: StringProperty(
        name=&quot;Label&quot;,
        default=&quot;&quot;,
    )
    idname: StringProperty(
        name=&quot;idname&quot;,
        default=&quot;&quot;,
    )
    icon_value: IntProperty(
        name=&quot;Icon value&quot;,
        default=0,
    )
    index: IntProperty(
        name='index',
        default=0
    )
    is_preset: BoolProperty(
        name='Is preset',
        default=False
    )
    mode: StringProperty()

And this property group is registered as Type of a CollectionProperty in register def
bpy.types.Scene.favit = CollectionProperty(type=Favourites)

I want the list of data in bpy.context.scene.favit  to be stored in a json.
If you don't need to write out default value, just use items() like dictionary.
Unless you assign it, Blender will not create an entry for them.
import bpy
import json

data = [
    prop.items()
    for prop in bpy.context.scene.favit
]

print(json.dumps(data))  # save this string to json file


output:
[[[&quot;index&quot;, 1], [&quot;label&quot;, &quot;hello world&quot;]], [[&quot;label&quot;, &quot;cool world&quot;]]]

The output format is same as [key, value] in a list,
once you want to write back to blender,
json_string = '''[[[&quot;index&quot;, 1], [&quot;label&quot;, &quot;hello world&quot;]], [[&quot;label&quot;, &quot;cool world&quot;]]]'''
data = json.loads(json_string)
for prop_list in data:
    prop = bpy.context.scene.favit.add()
    for key, value in prop_list:
        prop[key] = value