Export the layout of connected devices as Json with c#

Hello,

I have the problem that a user is using an input device, that is not working correctly. I would send him a small Unity program, that should save the device layout info (in fact what i see in the Input Debugger - State window) as ascii file, so that he can send it back to me an I can create a custom input device for him.

My question is: Is it possible to get the used layout of all connected devices as Json string?

    // Start is called before the first frame update
    void Start()
    {
        int i = 0;
        foreach (var each_device in InputSystem.devices)
        {
            // getting description works,
            using (StreamWriter stream = new StreamWriter("device" + i++ + ".txt", true))
                stream.Write(each_device.description.ToJson());

            // but how to get layout as Json?
            //....
        }
    }

Regards
Zulu

foreach (var device in InputSystem.devices)
{
    var layout = InputSystem.LoadLayout(device.layout);
    if (layout != null)
        var json = layout.ToJson();
}

Thank You!

Sorry for answering another question, but I need also the HID Descriptor info, but the cast does not work:

foreach (var device in InputSystem.devices)
{
    if (device.description.interfaceName == "HID")
        var json = ((HID)device).hidDescriptor.ToJson();
}

Not all HIDs are turned into HID InputDevices. Only those created by the generic HID fallback.

You can get the HID descriptor in JSON form simply from InputDeviceDescription.capabilities.

foreach (var device in InputSystem.devices)
{
    // For HIDs, this is the HID descriptor.
    var caps = device.capabilities;