Custom sensor with multiple attributes

Dear All,
I was wondering if it is possible to create a custom (mqtt) sensor with a value and multiple attributes. Like pretty much any other sensor.

The use case:
I get a json string in a specific topic, and I so far I have been creating sensors for each property I want to use in HA. I don’t think this is an efficient way of doing this, but I can’t figure out what to do. I can create an mqtt sensor which has a state and an attribute, but I need more than one attribute.

Is this something that is doable in a straightforward way? Maybe I don’t think of something obvious…?

Thanks for any pointers in advance!

It would help if you shared a sample sensor configuration and MQTT payload.

I’m sorry, I should have given more info…
This is a sample payload:

{
    "System": {
        "Hostname": "myhost",
        "TimeStamp": "Sat Jul 15 09:49:01 AM EEST 2023",
        "Architecture": "x86_64",
        "Uptime": "1 week, 14 hours, 43 minutes",
        "Load1": 0.02,
        "Load5": 0.07,
        "Load15": 0.02,
        "LastUpdated": "Jul 1 07:00"
    },
    "CPU": {
        "CPUs": 2,
        "CoresPerSocket": 1,
        "ThreadsPerCore": 1,
        "OSPretty": "Debian GNU/Linux 12 (bookworm)"
    },
    "Memory": {
        "TotalMemory": 2527512,
        "FreeMemory": 187820
    },
    "Storage": {
        "TotalDiskSpace": 59233540,
        "FreeDiskSpace": 48872024,
        "TotalSwap": 2621436,
        "FreeSwap": 2362840
    },
    "Network": {
        "IPAddress": "1.2.3.4"
    }
}

So far I have 2 ways of getting all the values in HA:

  1. Creating a sensor that has some value in its state and the whole json as an attribute, like this:
- name: All
  state_topic: "viktak/alonisos"
  value_template: "{{ '%.1f' | format(( 1 - value_json['Storage']['FreeDiskSpace'] / value_json['Storage']['TotalDiskSpace'] ) * 100|float)  }}"
  unit_of_measurement: "%"
  json_attributes_topic: "viktak/alonisos"
  icon: mdi:harddisk
  1. Creating multiple sensors that each have one of the values as their state, like this:
- name: Disk Usage Percent
  state_topic: "viktak/alonisos"
  value_template: "{{ '%.1f' | format(( 1 - value_json['Storage']['FreeDiskSpace'] / value_json['Storage']['TotalDiskSpace'] ) * 100|float)  }}"
  unit_of_measurement: "%"
  icon: mdi:harddisk

I feel this is not very efficient (for both creating all those sensors and for HA itself). I just don’t know how to combine them in a single sensor other than the first method.

What I would like is to get a single sensor with several attributes, like many others that various integrations provide. I’m happy to create a new integration, I just don’t want to reinvent the wheel.