Transfer part of the document and insert into another document (from a new bucket) in a new format

Hi all,

I have to move following part of documents (the type part) from documents where exits:

{
	"id": "id1",
...
	  "type": {
		"category": {
			"A": {
				"settings": {
					"_value": "{\"no\":1,\"max\":1,\"last\":1568123964693}"
				}
			}
		},
		"B": {
			"settings": {
				"_value": "{\"no\":1,\"max\":1,\"last\":1568123964693}"
			}
		}
	}
 ...
}

into a new format in a new bucket, like below

{
  	"id": "id1",
  	"types": {
  		"categories": [{
  				"name ": "A.settings",
  				"no": 1,
  				"max": 1,
  				"last": "1568123964693"
  			},
  			{
  				"name ": "B.settings",
  				"no": 1,
  				"max": 1,
  				"last": "1568123964693"
  			}
  		]
  	}
  }

How can I achieve this?
I’ve tried using INSERT-SELECT queries, but I couldn’t do the select to return the data in new format.

Thanks in advance for any pointers.

INSERT INTO default VALUES("k01", { "id": "id1", "f1":"f1", "type": { "category": { "A": { "settings": { "_value": '{"no":1,"max":1,"last":1568123964693}' } },  "B": { "settings": { "_value": '{"no":1,"max":1,"last":1568123964693}' } }} , "subf1":"subf1"} });
SELECT  OBJECT_ADD(OBJECT_REMOVE(d,"type"),"types", OBJECT_ADD(OBJECT_REMOVE(d.type,"category"),"categories",cs)) AS doc
FROM default AS d
LET cs = ARRAY OBJECT_ADD(DECODE_JSON(v.val.settings._value),"name", v.name||".settings") FOR v IN OBJECT_PAIRS(d.type.category) END
;