rest api – How to register post meta with multi level arrays?

I’m tringing to register post meta with object options under main object trim_levels to be used with REST API.


register_post_meta('vehicle', 'trim_levels', (
  'type'         => 'array',
  'description'  => 'Model trim levels.',
  'single'       => true,
  'show_in_rest' => array(
    'schema' => array(
      'items' => array(
        'type'       => 'object',
        'properties' => array(
          'title'    => array(
            'type' => 'string',
          ),
          'features' => array(
            'type'   => 'array'
          ),
          'options' => array(
            'type'   => 'object',
            'properties' => array(
              'engine'    => array(
                'type' => 'string',
              ),
              'horse_power' => array(
                'type'   => 'string'
              ),
              'transmission' => array(
                'type'   => 'string'
              )
            ),
          ),
        ),
      ),
    ),
  ),
));

POST request example with REST API:


{
  "title": "Tucson",
  "status": "publish",
  "meta": {
    "trim_levels": (
      {
        "title": "Comfort",
        "features": (
          "Feature 1",
          "Feature 2",
          "Feature 3"
        ),
        "options": (
          {
            "engine": "1,6 T-GDI",
            "horse_power": "177",
            "transmission": "automatic"
          },
          {
            "engine": "1,6 GDI",
            "horse_power": "160",
            "transmission": "manual"
          }
        )
      },
      {
        "title": "Premium",
        "features": ( 
          "Feature 1",
          "Feature 2",
          "Feature 3"
        ),
        "options": (
          {
            "engine": "1,6 T-GDI",
            "horse_power": "177",
            "transmission": "automatic"
          }
        )
      }
    )
  }
}

Response:


{
    "code": "rest_invalid_param",
    "message": "0 is not a valid property of Object.",
    "data": {
        "status": 400
    }
}

I am struggling to find a way to save the options as an associative arrays.