Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file yojson_conv.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255openStdLabelsopenMoreLabelsopen!Yojsontypet=Yojson.Safe.tletyojson_of_unit():t=`Nullletyojson_of_boolb:t=`Boolbletyojson_of_stringstr:t=`Stringstrletyojson_of_bytesbytes:t=`String(Bytes.to_stringbytes)letyojson_of_charc:t=`String(String.make1c)letyojson_of_intn:t=`Intnletyojson_of_floatn:t=`Floatnletyojson_of_int32(n:Int32.t):t=`Intlit(Int32.to_stringn)letyojson_of_int64(n:Int64.t):t=`Intlit(Int64.to_stringn)letyojson_of_nativeintn:t=`Intlit(Nativeint.to_stringn)letyojson_of_refyojson_of__arf=yojson_of__a!rfletyojson_of_lazy_tyojson_of__alv=yojson_of__a(Lazy.forcelv)letyojson_of_optionyojson_of__a=function|Somex->yojson_of__ax|None->`Null;;letyojson_of_pairyojson_of__ayojson_of__b(a,b)=`List[yojson_of__aa;yojson_of__bb];;letyojson_of_tripleyojson_of__ayojson_of__byojson_of__c(a,b,c)=`List[yojson_of__aa;yojson_of__bb;yojson_of__cc];;(* List.rev (List.rev_map ...) is tail recursive, the OCaml standard
library List.map is NOT. *)letyojson_of_listyojson_of__alst=`List(List.rev(List.rev_map~f:yojson_of__alst))letyojson_of_arrayyojson_of__aar=letlst_ref=ref[]infori=Array.lengthar-1downto0dolst_ref:=yojson_of__aar.(i)::!lst_refdone;`List!lst_ref;;letyojson_of_hashtblyojson_of_keyyojson_of_valhtbl=letcoll~key:k~data:vacc=`List[yojson_of_keyk;yojson_of_valv]::accin`List(Hashtbl.foldhtbl~init:[]~f:coll);;letyojson_of_opaque_=`String"<opaque>"letyojson_of_fun_=`String"<fun>"exceptionOf_yojson_errorofexn*tletrecord_check_extra_fields=reftrueletof_yojson_error_exnexcyojson=raise(Of_yojson_error(exc,yojson))letof_yojson_errorwhatyojson=raise(Of_yojson_error(Failurewhat,yojson))letunit_of_yojsonyojson=matchyojsonwith|`Null->()|_->of_yojson_error"unit_of_yojson: `Null needed"yojson;;letbool_of_yojsonyojson=matchyojsonwith|`Boolv->v|_->of_yojson_error"bool_of_yojson: true/false needed"yojson;;letstring_of_yojsonyojson=matchyojsonwith|`Stringstr->str|_->of_yojson_error"string_of_yojson: string needed"yojson;;letbytes_of_yojsonyojson=matchyojsonwith|`Stringstr->Bytes.of_stringstr|_->of_yojson_error"bytes_of_yojson: string needed"yojson;;letchar_of_yojsonyojson=matchyojsonwith|`Stringstr->ifString.lengthstr<>1thenof_yojson_error"char_of_yojson: string must contain one character only"yojson;str.[0]|_->of_yojson_error"char_of_yojson: string of size one needed"yojson;;letint_of_yojsonyojson=matchyojsonwith|`Intv->v|_->of_yojson_error"int_of_yojson: integer needed"yojson;;letfloat_of_yojsonyojson=matchyojsonwith|`Floatv->v|`Inti->float_of_inti|`Intlitstr->float_of_stringstr|_->of_yojson_error"float_of_yojson: float needed"yojson;;letint32_of_yojsonyojson=matchyojsonwith|`Intlitstr->Int32.of_stringstr|`Intv->Int32.of_intv|_->of_yojson_error"int32_of_yojson: integer needed"yojson;;letint64_of_yojsonyojson=matchyojsonwith|`Intlitstr->Int64.of_stringstr|`Intv->Int64.of_intv|_->of_yojson_error"int64_of_yojson: integer needed"yojson;;letnativeint_of_yojsonyojson=matchyojsonwith|`Intlitstr->Nativeint.of_stringstr|`Intv->Nativeint.of_intv|_->of_yojson_error"nativeint_of_yojson: integer needed"yojson;;letref_of_yojsona__of_yojsonyojson=ref(a__of_yojsonyojson)letlazy_t_of_yojsona__of_yojsonyojson=Lazy.from_val(a__of_yojsonyojson)letoption_of_yojsona__of_yojsonyojson=matchyojsonwith|`Null->None|el->Some(a__of_yojsonel);;letpair_of_yojsona__of_yojsonb__of_yojsonyojson=matchyojsonwith|`List[a_yojson;b_yojson]->leta=a__of_yojsona_yojsoninletb=b__of_yojsonb_yojsonina,b|_->of_yojson_error"pair_of_yojson: invalid format"yojson;;lettriple_of_yojsona__of_yojsonb__of_yojsonc__of_yojsonyojson=matchyojsonwith|`List[a_yojson;b_yojson;c_yojson]->leta=a__of_yojsona_yojsoninletb=b__of_yojsonb_yojsoninletc=c__of_yojsonc_yojsonina,b,c|_->of_yojson_error"triple_of_yojson: invalid format"yojson;;letlist_of_yojsona__of_yojsonyojson=matchyojsonwith|`Listlst->letrev_lst=List.rev_maplst~f:a__of_yojsoninList.revrev_lst|_->of_yojson_error"list_of_yojson: list needed"yojson;;letarray_of_yojsona__of_yojsonyojson=matchyojsonwith|`List[]->[||]|`List(h::t)->letlen=List.lengtht+1inletres=Array.makelen(a__of_yojsonh)inletrecloopi=function|[]->res|h::t->res.(i)<-a__of_yojsonh;loop(i+1)tinloop1t|_->of_yojson_error"array_of_yojson: list needed"yojson;;lethashtbl_of_yojsonkey_of_yojsonval_of_yojsonyojson=matchyojsonwith|`Listlst->lethtbl=Hashtbl.create0inletact=function|`List[k_yojson;v_yojson]->Hashtbl.addhtbl~key:(key_of_yojsonk_yojson)~data:(val_of_yojsonv_yojson)|_->of_yojson_error"hashtbl_of_yojson: tuple list needed"yojsoninList.iterlst~f:act;htbl|_->of_yojson_error"hashtbl_of_yojson: list needed"yojson;;letopaque_of_yojsonyojson=of_yojson_error"opaque_of_yojson: cannot convert opaque values"yojson;;letfun_of_yojsonyojson=of_yojson_error"fun_of_yojson: cannot convert function values"yojson;;moduleResult=structtype'at=('a,string)resultletunpack(f:Safe.t->'at)x:'a=matchfxwith|Okv->v|Errorstr->of_yojson_errorstrx;;letof_exn=function|Of_yojson_error(Failures,_json)->Errors|exn->Error(Printexc.to_stringexn);;letpack(f:Safe.t->'a)x:'at=matchfxwith|v->Okv|exceptionexn->of_exnexn;;endmodulePrimitives=structletyojson_of_array=yojson_of_arrayletarray_of_yojson=array_of_yojsonletyojson_of_bool=yojson_of_boolletbool_of_yojson=bool_of_yojsonletyojson_of_char=yojson_of_charletchar_of_yojson=char_of_yojsonletyojson_of_float=yojson_of_floatletfloat_of_yojson=float_of_yojsonletyojson_of_int=yojson_of_intletint_of_yojson=int_of_yojsonletyojson_of_int32=yojson_of_int32letint32_of_yojson=int32_of_yojsonletyojson_of_int64=yojson_of_int64letint64_of_yojson=int64_of_yojsonletyojson_of_list=yojson_of_listletlist_of_yojson=list_of_yojsonletyojson_of_nativeint=yojson_of_nativeintletnativeint_of_yojson=nativeint_of_yojsonletyojson_of_option=yojson_of_optionletoption_of_yojson=option_of_yojsonletyojson_of_ref=yojson_of_refletref_of_yojson=ref_of_yojsonletyojson_of_string=yojson_of_stringletstring_of_yojson=string_of_yojsonletyojson_of_bytes=yojson_of_bytesletbytes_of_yojson=bytes_of_yojsonletyojson_of_unit=yojson_of_unitletunit_of_yojson=unit_of_yojsonletyojson_of_lazy_t=yojson_of_lazy_tletlazy_t_of_yojson=lazy_t_of_yojsonletyojson_of_hashtbl=yojson_of_hashtbllethashtbl_of_yojson=hashtbl_of_yojsonend