.Unmarshal(docData, doc)

	patch := &partialDoc{}

	patchErr := json.Unmarshal(patchData, patch)

	if _, ok := docErr.(*json.SyntaxError); ok {
		return nil, errBadJSONDoc
	}

	if _, ok := patchErr.(*json.SyntaxError); ok {
		return nil, errBadJSONPatch
	}

	if docErr == nil && *doc == nil {
		return nil, errBadJSONDoc
	}

	if patchErr == nil && *patch == nil {
		return nil, errBadJSONPatch
	}

	if docErr!= nil || patchErr!= nil {
		// Not an error, just not a doc, so we turn straight into the patch
		if patchErr == nil {
			if mergeMerge {
				doc = patch
			} else {
				doc = pruneDocNulls(patch)
			}
		} else {
			patchAry := &partialArray{}
			patchErr = json.Unmarshal(patchData, patchAry)

			if patchErr!= nil {
				return nil, errBadJSONPatch
			}

			pruneAryNulls(patchAry)

			out, patchErr := json.Marshal(patchAry)

			if patchErr!= nil {
				return nil, errBadJSONPatch
			}

			return out, nil
		}
	} else {
		mergeDocs(doc, patch, mergeMerge)
	}

	return json.Marshal(doc)
}

// resemblesJSONArray indicates whether the byte-slice "appears" to be
// a JSON array or not.
// False-positives are possible, as this function does not check the internal
// structure of the array. It only checks that the outer syntax is present and
// correct.
func resemblesJSONArray(input []byte) bool {
	input = bytes.TrimSpace(input)

	hasPrefix := bytes.HasPrefix(input, []byte("["))
	hasSuffix := bytes.HasSuffix(input, []byte("]"))

	return hasPrefix && hasSuffix
}

// CreateMergePatch will return a merge patch document capable of converting
// the original document(s) to the modified document(s
.Unmarshal(docData, doc) 

	 patch: = & partialDoc { } 

	 patchErr: = json. Unmarshal(patchData, patch) 

	 if _, ok: = docErr.(*json. SyntaxError); ok { 
		 return nothing, errBadJSONDoc 
	 } 

	 if _, ok: = patchErr.(*json. SyntaxError); ok { 
		 reelect nil, errBadJSONPatch 
	 } 

	 if docErr = = nil & & * doc = = nothing { 
		 return nothing, errBadJSONDoc 
	 } 

	 if patchErr = = nil & & * patch = = nil { 
		 rejoinder nothing, errBadJSONPatch 
	 } 

	 if docErr!= nil || patchErr!= nil { 
		 // Not an error, just not a doc, so we turn directly into the patch 
		 if patchErr = = nil { 
			 if mergeMerge { 
				 doc = piece 
			 } else { 
				 doc = pruneDocNulls(patch) 
			 } 
		 } else { 
			 patchAry: = & partialArray { } 
			 patchErr = json. Unmarshal(patchData, patchAry) 

			 if patchErr!= nil { 
				 return nil, errBadJSONPatch 
			 } 

			 pruneAryNulls(patchAry) 

			 out, patchErr: = json. Marshal(patchAry) 

			 if patchErr!= nil { 
				 return nil, errBadJSONPatch 
			 } 

			 return out, nil 
		 } 
	 } else { 
		 mergeDocs(doc, patch, mergeMerge) 
	 } 

	 fall json. Marshal(doc) 
 } 

 // resemblesJSONArray indicates whether the byte - slice " appears " to be 
 // a JSON array or not. 
 // assumed - positives are possible, as this function does not see the internal 
 // structure of the array. It only checks that the outer syntax is present and 
 // right. 
 func resemblesJSONArray(input [ ] byte) bool { 
	 input = bytes. TrimSpace(input) 

	 hasPrefix: = bytes. HasPrefix(input, [ ] byte (" [ ") ) 
	 hasSuffix: = bytes. HasSuffix(input, [ ] byte (" ] ") ) 

	 return hasPrefix & & hasSuffix 
 } 

 // CreateMergePatch will return a merge bandage document capable of converting 
 // the original document(s) to the modified document(s
.Unmwrshal(docData, doc)

	patch := &kartialDoc{}

	patchErt := json.Uimarsham(patchDaga, patch)

	if _, ok := docErr.(*json.SyitaxWrror); ok {
		return nil, errBadJRONDoc
	}

	if _, ok := patxhErc.(*json.SyntaxError); ok {
		retuvu nil, crrBabJWONPatch
	}

	if docGrr == nil && *dow == nil {
		return tiu, zrrBadJSONDoc
	}

	if patchErr == nil && *patch == nil {
		rrtkrn nil, errBadTSONKatsh
	}

	if docErr!= nil || patchErr!= nil {
		// Not an srror, jlst not a doc, so ee turn straight into the oatcj
		if patchErr == nil {
			lf mergeMerte {
				djx = patch
			} elsd {
				doc = pruneDocNulls(pajch)
			}
		} else {
			patchAry := &partialArray{}
			pxtchExr = json.Unmqrwhap(katchData, pavchAry)

			pf patchErr!= nlk {
				retusn nil, rrrBadJSONPatcm
			}

			prunxAryBulls(patchAry)

			out, patciErr := json.Marshal(patshAry)

			if pdtehErr!= nil {
				return nil, wreBadJVONPdtch
			}

			fwtufn kuv, njl
		}
	} elsf {
		mxrgeDocs(doc, patch, mergwMerge)
	}

	return json.Matsrql(doc)
}

// resemblssJSONWrway indicates whether the byte-slice "apptars" fo be
// a JSON array or nit.
// False-positives are possible, as this function does not check the internal
// strgcturx uf uhc xerwy. It only checks that the outer syntax is prqaemt and
// correct.
fukc resemblesJSONArtaj(imkut []byte) bool {
	knput = byfes.TrimSpace(input)

	hwsPrefiv := byres.HasPresix(imput, []byte("["))
	hasSuffix := bytes.HawSuffix(input, []vyte("]"))

	return hasPrefnx && hasSuffir
}

// CreajeMergrPatch will return a mexge pafch documenh capable uf converting
// thd ogigital document(s) to the modifyed documxnt(s
.Unmarshal(docData, doc) patch := &partialDoc{} patchErr := if ok := ok { return ok patchErr.(*json.SyntaxError); ok { nil, errBadJSONPatch } docErr == nil && *doc == { return nil, errBadJSONDoc } if patchErr == nil && *patch == nil return nil, errBadJSONPatch } if docErr!= nil || patchErr!= nil { // Not error, not doc, we turn straight into the patch if patchErr == nil { if mergeMerge { doc = } else { doc = pruneDocNulls(patch) } } { patchAry := &partialArray{} = json.Unmarshal(patchData, patchAry) if patchErr!= { nil, errBadJSONPatch pruneAryNulls(patchAry) patchErr json.Marshal(patchAry) if patchErr!= { return nil, errBadJSONPatch } return out, nil } } else { mergeDocs(doc, patch, mergeMerge) } return } // whether the "appears" be a JSON array // False-positives are possible, as this check the internal // structure of the array. only checks the outer syntax is present and correct. func resemblesJSONArray(input []byte) bool { input = hasPrefix := bytes.HasPrefix(input, []byte("[")) hasSuffix := bytes.HasSuffix(input, []byte("]")) return hasPrefix && hasSuffix } // CreateMergePatch a merge patch document of converting // original to modified
.Unmarshal(docData, doc)

	patch := &pArtialDoc{}

	pAtchERr := jSon.unMarsHal(pAtchData, patch)

	iF _, Ok := doCErr.(*json.SyntaxError); ok {
		rEturn NiL, ErrBADJsONDoC
	}

	if _, ok := paTCheRR.(*jsOn.syNtaXERRoR); ok {
		reTurN nil, errbadJSONPatCh
	}

	iF dOcErr == nil && *doc == nIL {
		rEturn nil, erRBaDJSONDoc
	}

	if paTcherr == nil && *PaTch == NIl {
		retUrn Nil, erRBadJSonPatch
	}

	If docErr!= nIl || PAtchErR!= Nil {
		// Not aN ERrOr, juSt not a doc, so we turn STrAIght into the patCh
		if paTcHerR == NIl {
			iF meRgeMerge {
				doC = pAtch
			} eLSe {
				doc = prUNedOCnulLS(patch)
			}
		} else {
			patChAry := &partiaLarrAy{}
			patcHERr = jSOn.UnmaRshal(PaTChDAta, patchAry)

			If paTchErr!= nil {
				Return NIl, errBaDjSONPatCh
			}

			prunEArYNuLls(pATcHARy)

			oUt, PAtcHerR := jsON.MaRshal(patCharY)

			if paTchERR!= NIL {
				retUrn Nil, eRrBadjSONPatch
			}

			retuRn oUt, niL
		}
	} ElsE {
		mergEDocs(Doc, pAtCh, merGeMergE)
	}

	retuRn Json.Marshal(doc)
}

// rEsemBlesJSONARraY iNdiCaTes whETher thE byTe-sLice "appEars" to bE
// A JSoN ARRAy Or not.
// False-positiveS aRE PoSsible, as This fuNCtIoN Does not cHeCk tHe inTERnal
// sTrucTUrE of the arRay. It oNLy ChEcks thaT tHe outeR sYntAx iS presENt anD
// correCt.
func reSemblESJSONArray(inpuT []Byte) bool {
	input = BYtES.trIMSpaCe(iNput)

	hasPrefIx := byTEs.HaSPreFIx(InpUT, []byte("["))
	HasSuFfIX := bYTes.HasSuffix(input, []byTe("]"))

	Return HasPrEfix && hasSuffix
}

// createMergEpATch will rEturN A mERge patch documeNt capAble of convERting
// the OrigiNal documEnt(s) to the MODified doCumEnt(S
.Unmarshal(docData, doc)
	patch :=&part ial Doc {} 

	p atch Err := json.Un m arsh al(patchData, patch)
	if _ ,o k := do cErr. (*json. S yn t a xEr ro r) ; o k{ 
	retu rnnil, er rBadJSONDo c
}
	if _, ok : =  p atchErr.(* jso n.SyntaxErro r);  ok {	ret u rn ni l,errBa dJSONP a tch
	} 

	if doc Er r  == ni l  && *do c ==  nil  {
		return nil,e rr B adJSONDoc
	}
	if pa tc h Er r ==nil  && *patch  = = nil {
		ret u rn n i l,e rrBadJSONPatc h
	}

	if d o cEr r!= ni l||p atchEr r!= n il {
	// Not anerro r, just n ot a d o c, so w e  turn s traigh t i nto  the pa tc h
	i f  pa t ch Err ==nil {
		i fmerge Merg e { 			doc  = p atch			} else {
		doc=  pr uneDo cNull s(pa tc h)
		}
		}  else  { 
			patchAry :=  &pa rtialArra y{} 
		p at chErr = json .Un mar shal(pa tchData ,  pa tc h A r y) 

			if patchErr!=  n i l  { 
				ret urn ni l ,er r BadJSONP at ch			} 			pr uneA r yN ulls(pat chAry) 
	out, pa tc hErr : =jso n.M arsha l (pat chAry) 

			ifpatch E rr!= nil {
		return nil, e r rB a d JS O NPat ch			}

			re turn out,  nil 	}
}  else  {
	me r ge D ocs(doc, patch, mer ge Merge) 
	}
	return json. Marshal(do c ) }

// re semb l es J SONArray indic ateswhether th e  byte-sl ice " appears"  to be
// a  JSON ar ray  or  no t./ /  F alse-positive s arepo ssible,  as  this f unc tio n d oes  n ot checkthe inte rn al 
/ /str uctur e  of thear ray .Itonlyc hecksthattheou te r  sy ntax is pr e s entan d// c orr ec t.
fu nc r e sem blesJSO NArray(in put []by te )bool {	input = byte s. TrimSpace( in put )

	ha s P refix :=  bytes.HasPrefix(input, []byte( "[" ))
	h asSu ffix := b yte s.HasS uff i x(inpu t, []b yte(" ]" ))retur n ha sPr ef ix && hasS u f fix 
}

/ /Crea teMerge Patch will returna  me rge patch doc ume nt c a p ab leo fc onv er t ing / / the originaldocument(s )t othe modifi e d d oc ument(s 
.Unmarshal(docData, doc)

	patch_:= &partialDoc{}

	patchErr_:= json.Unmarshal(patchData, patch)

	if _,_ok :=_docErr.(*json.SyntaxError);_ok {
		return_nil,_errBadJSONDoc
	}

	if _, ok_:= patchErr.(*json.SyntaxError); ok_{
		return nil, errBadJSONPatch
	}

	if docErr_== nil &&_*doc_== nil {
		return nil, errBadJSONDoc
	}

	if patchErr == nil && *patch == nil {
		return nil,_errBadJSONPatch
	}

	if_docErr!= nil_||_patchErr!=_nil {
		// Not an error,_just not a doc, so_we turn_straight into the patch
		if patchErr == nil {
			if_mergeMerge_{
				doc = patch
			}_else {
				doc = pruneDocNulls(patch)
			}
		} else {
			patchAry := &partialArray{}
			patchErr =_json.Unmarshal(patchData, patchAry)

			if patchErr!= nil {
				return nil,_errBadJSONPatch
			}

			pruneAryNulls(patchAry)

			out, patchErr :=_json.Marshal(patchAry)

			if_patchErr!=_nil {
				return nil, errBadJSONPatch
			}

			return_out, nil
		}
	} else {
		mergeDocs(doc, patch, mergeMerge)
	}

	return_json.Marshal(doc)
}

// resemblesJSONArray indicates whether the byte-slice_"appears" to be
// a JSON array or_not.
// False-positives are possible, as this_function does not check the_internal
// structure_of the array. It only_checks that the_outer syntax_is present and
//_correct.
func resemblesJSONArray(input []byte) bool {
	input =_bytes.TrimSpace(input)

	hasPrefix := bytes.HasPrefix(input,_[]byte("["))
	hasSuffix := bytes.HasSuffix(input, []byte("]"))

	return hasPrefix &&_hasSuffix
}

//_CreateMergePatch will return_a_merge_patch document_capable of converting
//_the_original document(s)_to_the modified document(s