op:insert-named-child( $patch-builder-plan as map:map, $path as xs:string, $key as xs:string, $content as node() ) as map:map
This method is specific for JSON and inserts a key/value pair to an object.
xquery version "1.0-ml"; import module namespace op="http://marklogic.com/optic" at "/MarkLogic/optic.xqy"; declare option xdmp:update "true"; let $doc-descriptors := ( map:entry("uri", '/optic/update/write4.json') =>map:with("doc", xdmp:unquote("{key:{ key2: 2}}")), map:entry("uri", '/optic/update/write5.xml') =>map:with("doc",xdmp:unquote("{key:{ key2: 2}}")) =>map:with("collections", ("write")) ) return op:from-doc-descriptors($doc-descriptors) =>op:patch(op:col("doc"),op:patch-builder("/") =>op:insert-named-child("key","key3",3) ) =>op:write(op:doc-cols()) =>op:result()