123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226type'aocaml_array='aarrayletinput_filefnameread=letic=open_in_binfnameintryletx=readicinclose_inic;xwithe->close_in_noerric;raiseeletoutput_filefnamewrite=letoc=open_out_binfnameintrywriteoc;close_outocwithe->close_out_noerroc;raiseemoduleBiniou=structtype'areader=Bi_inbuf.t->'atype'awriter=Bi_outbuf.t->'a->unitletfrom_channel?len?(shrlen=0)readic=letib=Bi_inbuf.from_channel?len~shrlenicinreadibletfrom_file?len?(shrlen=0)readfname=input_filefname(funic->from_channel?len~shrlenreadic)letto_channel?len?(shrlen=0)writeocx=letob=Bi_outbuf.create_channel_writer?len~shrlenocinwriteobx;Bi_outbuf.flush_channel_writerobletto_file?len?(shrlen=0)writefnamex=output_filefname(funoc->to_channel?len~shrlenwriteocx)endmoduleJson=structtype'areader=Yojson.Safe.lexer_state->Lexing.lexbuf->'atype'awriter=Bi_outbuf.t->'a->unitletfinishlslexbuf=Yojson.Safe.read_spacelslexbuf;ifnot(Yojson.Safe.read_eoflexbuf)thenYojson.json_error"Junk after end of JSON value"letfrom_lexbuf?(stream=false)readlslexbuf=Yojson.Safe.read_spacelslexbuf;letx=ifYojson.Safe.read_eoflexbufthenraiseYojson.End_of_inputelsereadlslexbufinifnotstreamthenfinishlslexbuf;xletfrom_string?buf?fname?lnumreads=letlexbuf=Lexing.from_stringsinletls=Yojson.Safe.init_lexer?buf?fname?lnum()infrom_lexbufreadlslexbufletfrom_channel?buf?fname?lnumreadic=letlexbuf=Lexing.from_channelicinletls=Yojson.Safe.init_lexer?buf?fname?lnum()infrom_lexbufreadlslexbufletfrom_file?buf?fname:src?lnumreadfname=letfname0=matchsrcwithNone->fname|Somes->sininput_filefname(funic->from_channel?buf~fname:fname0?lnumreadic)letstream_from_lexbuf?(fin=fun()->())readlslexbuf=letstream=Sometrueinletrecfi=trySome(from_lexbuf?streamreadlslexbuf)withYojson.End_of_input->fin();None|e->(tryfin()with_->());raiseeinStream.fromfletstream_from_string?buf?fin?fname?lnumreadic=letlexbuf=Lexing.from_stringicinletls=Yojson.Safe.init_lexer?buf?fname?lnum()instream_from_lexbuf?finreadlslexbufletstream_from_channel?buf?fin?fname?lnumreadic=letlexbuf=Lexing.from_channelicinletls=Yojson.Safe.init_lexer?buf?fname?lnum()instream_from_lexbuf?finreadlslexbufletstream_from_file?buf?(fin=fun()->())?fname:src?lnumreadfname=letfname0=matchsrcwithNone->fname|Somes->sinletic=open_in_binfnameinletfin()=close_in_noerric;fin()instream_from_channel?buf~fin~fname:fname0?lnumreadicletlist_from_string?buf?fin?fname?lnumreadic=letstream=stream_from_string?buf?fin?fname?lnumreadicinletacc=ref[]inStream.iter(funx->acc:=x::!acc)stream;List.rev!accletlist_from_channel?buf?fin?fname?lnumreadic=letstream=stream_from_channel?buf?fin?fname?lnumreadicinletacc=ref[]inStream.iter(funx->acc:=x::!acc)stream;List.rev!accletlist_from_file?buf?fname:src?lnumreadfname=letfname0=matchsrcwithNone->fname|Somes->sinletic=open_in_binfnameinletfin()=close_in_noerricinlist_from_channel?buf~fin~fname:fname0?lnumreadicletto_string?(len=1024)writex=letob=Bi_outbuf.createleninwriteobx;Bi_outbuf.contentsobletto_channel?lenwriteocx=Biniou.to_channel?len~shrlen:0writeocxletto_file?lenwritefnamex=Biniou.to_file?len~shrlen:0writefnamexletstream_to_string?(len=1024)?(lf="\n")writestream=letob=Bi_outbuf.createleninStream.iter(funx->writeobx;Bi_outbuf.add_stringoblf)stream;Bi_outbuf.contentsobletstream_to_channel?len?(lf="\n")writeocstream=letob=Bi_outbuf.create_channel_writer?len~shrlen:0ocinStream.iter(funx->writeobx;Bi_outbuf.add_stringoblf)stream;Bi_outbuf.flush_channel_writerobletstream_to_file?len?lfwritefnamestream=output_filefname(funoc->stream_to_channel?len?lfwriteocstream)letlist_to_string?len?lfwritel=stream_to_string?len?lfwrite(Stream.of_listl)letlist_to_channel?len?lfwriteocl=stream_to_channel?len?lfwriteoc(Stream.of_listl)letlist_to_file?len?lfwritefnamel=stream_to_file?len?lfwritefname(Stream.of_listl)letpreset_unknown_field_handlerlocname=letmsg=Printf.sprintf"Found unknown JSON field %s while expecting type defined at: %s"namelocinfailwithmsgletunknown_field_handler=refpreset_unknown_field_handlerletpreset_constr_mismatch_handlerconstr_fieldconstr_constrvalue_fieldvalue_constr=letmsg=Printf.sprintf"Field %s has constructor %s but field %s expects constructor %s"value_fieldvalue_constrconstr_fieldconstr_constrinAg_oj_run.errormsgletconstr_mismatch_handler=refpreset_constr_mismatch_handlerendmoduleValidation=structtypepath_elem=[`Fieldofstring|`Indexofint]typepath=path_elemlistletstring_of_pathl=String.concat""(List.rev_map(function|`Fields->"."^s|`Indexn->"["^string_of_intn^"]")l)typeerror={error_path:path;error_msg:stringoption;}leterror?msgpath={error_path=path;error_msg=msg;}letstring_of_errorx=letpath=string_of_pathx.error_pathinmatchx.error_msgwithNone->"Validation error; path = <root>"^path|Somemsg->Printf.sprintf"Validation error: %s; path = <root>%s"msgpathend