locala=true;localb=false;localc='json'localpairs,type,tostring,tonumber,getmetatable,setmetatable,rawset=pairs,type,tostring,tonumber,getmetatable,setmetatable,rawset;localerror,require,pcall,select=error,require,pcall,select;locald,e=math.floor,math.huge;localf,g,h,i,j,k,l,m=string.rep,string.gsub,string.sub,string.byte,string.char,string.find,string.len,string.format;localn=string.match;localo=table.concat;localp={version="dkjson 2.5"}ifbthen_G[c]=pend;localq=nil;pcall(function()localr=require"debug".getmetatable;ifrthengetmetatable=rendend)p.null=setmetatable({},{__tojson=function()return"null"end})localfunctions(t)localu,v,w=0,0,0;forx,yinpairs(t)doifx=='n'andtype(y)=='number'thenw=y;ify>uthenu=yendelseiftype(x)~='number'orx<1ord(x)~=xthenreturnfalseend;ifx>uthenu=xend;v=v+1endend;ifu>10andu>wandu>v*2thenreturnfalseend;returntrue,uend;localz={["\""]="\\\"",["\\"]="\\\\",["\b"]="\\b",["\f"]="\\f",["\n"]="\\n",["\r"]="\\r",["\t"]="\\t"}localfunctionA(B)localC=z[B]ifCthenreturnCend;localD,E,F,G=i(B,1,4)D,E,F,G=Dor0,Eor0,For0,Gor0;ifD<=0x7fthenC=Delseif0xc0<=DandD<=0xdfandE>=0x80thenC=(D-0xc0)*0x40+E-0x80elseif0xe0<=DandD<=0xefandE>=0x80andF>=0x80thenC=((D-0xe0)*0x40+E-0x80)*0x40+F-0x80elseif0xf0<=DandD<=0xf7andE>=0x80andF>=0x80andG>=0x80thenC=(((D-0xf0)*0x40+E-0x80)*0x40+F-0x80)*0x40+G-0x80elsereturn""end;ifC<=0xffffthenreturnm("\\u%.4x",C)elseifC<=0x10ffffthenC=C-0x10000;localH,I=0xD800+d(C/0x400),0xDC00+C%0x400;returnm("\\u%.4x\\u%.4x",H,I)elsereturn""endend;localfunctionJ(K,L,M)ifk(K,L)thenreturng(K,L,M)elsereturnKendend;localfunctionN(C)C=J(C,"[%z\1-\31\"\\\127]",A)if k(C,"[\194\216\220\225\226\239]")then C=J(C,"\194[\128-\159\173]",A)C=J(C,"\216[\128-\132]",A)C=J(C,"\220\143",A)C=J(C,"\225\158[\180\181]",A)C=J(C,"\226\128[\140-\143\168-\175]",A)C=J(C,"\226\129[\160-\175]",A)C=J(C,"\239\187\191",A)C=J(C,"\239\191[\176-\191]",A)end;return"\""..C.."\""end;p.quotestring=N;localfunctionO(K,P,v)localQ,R=k(K,P,1,true)ifQthenreturnh(K,1,Q-1)..v..h(K,R+1,-1)elsereturnKendend;localS,T;localfunctionU()S=n(tostring(0.5),"([^05+])")T="[^0-9%-%+eE"..g(S,"[%^%$%(%)%%%.%[%]%*%+%-%?]","%%%0").."]+"end;U()localfunctionV(W)returnO(J(tostring(W),T,""),S,".")end;localfunctionX(K)localW=tonumber(O(K,".",S))ifnotWthenU()W=tonumber(O(K,".",S))end;returnWend;localfunctionY(Z,_,a0)_[a0+1]="\n"_[a0+2]=f(" ",Z)a0=a0+2;returna0end;functionp.addnewline(a1)ifa1.indentthena1.bufferlen=Y(a1.levelor0,a1.buffer,a1.bufferlenor#a1.buffer)endend;locala2;localfunctiona3(a4,C,a5,a6,Z,_,a0,a7,a8,a1)locala9=type(a4)ifa9~='string'anda9~='number'thenreturnnil,"type '"..a9.."' is not supported as a key by JSON."end;ifa5thena0=a0+1;_[a0]=","end;ifa6thena0=Y(Z,_,a0)end;_[a0+1]=N(a4)_[a0+2]=":"returna2(C,a6,Z,_,a0+2,a7,a8,a1)end;localfunctionaa(ab,_,a1)locala0=a1.bufferlen;iftype(ab)=='string'thena0=a0+1;_[a0]=abend;returna0end;localfunctionac(ad,C,a1,_,a0,ae)ae=aeorad;localaf=a1.exception;ifnotafthenreturnnil,aeelsea1.bufferlen=a0;localag,ah=af(ad,C,a1,ae)ifnotagthenreturnnil,ahoraeend;returnaa(ag,_,a1)endend;functionp.encodeexception(ad,C,a1,ae)returnN("<"..ae..">")end;a2=function(C,a6,Z,_,a0,a7,a8,a1)localai=type(C)localaj=getmetatable(C)aj=type(aj)=='table'andaj;localak=ajandaj.__tojson;ifakthenifa7[C]thenreturnac('reference cycle',C,a1,_,a0)end;a7[C]=true;a1.bufferlen=a0;localag,ah=ak(C,a1)ifnotagthenreturnac('custom encoder failed',C,a1,_,a0,ah)end;a7[C]=nil;a0=aa(ag,_,a1)elseifC==nilthena0=a0+1;_[a0]="null"elseifai=='number'thenlocalal;ifC~=CorC>=eor-C>=ethenal="null"elseal=V(C)end;a0=a0+1;_[a0]=alelseifai=='boolean'thena0=a0+1;_[a0]=Cand"true"or"false"elseifai=='string'thena0=a0+1;_[a0]=N(C)elseifai=='table'thenifa7[C]thenreturnac('reference cycle',C,a1,_,a0)end;a7[C]=true;Z=Z+1;localam,v=s(C)ifv==0andajandaj.__jsontype=='object'thenam=falseend;localah;ifamthena0=a0+1;_[a0]="["forQ=1,vdoa0,ah=a2(C[Q],a6,Z,_,a0,a7,a8,a1)ifnota0thenreturnnil,ahend;ifQ<vthena0=a0+1;_[a0]=","endend;a0=a0+1;_[a0]="]"elselocala5=false;a0=a0+1;_[a0]="{"localan=ajandaj.__jsonorderora8;ifanthenlocalao={}v=#an;forQ=1,vdolocalx=an[Q]localy=C[x]ifythenao[x]=true;a0,ah=a3(x,y,a5,a6,Z,_,a0,a7,a8,a1)a5=trueendend;forx,yinpairs(C)doifnotao[x]thena0,ah=a3(x,y,a5,a6,Z,_,a0,a7,a8,a1)ifnota0thenreturnnil,ahend;a5=trueendendelseforx,yinpairs(C)doa0,ah=a3(x,y,a5,a6,Z,_,a0,a7,a8,a1)ifnota0thenreturnnil,ahend;a5=trueendend;ifa6thena0=Y(Z-1,_,a0)end;a0=a0+1;_[a0]="}"end;a7[C]=nilelsereturnac('unsupported type',C,a1,_,a0,"type '"..ai.."' is not supported by JSON.")end;returna0end;functionp.encode(C,a1)a1=a1or{}localap=a1.buffer;local_=apor{}a1.buffer=_;U()localag,ah=a2(C,a1.indent,a1.levelor0,_,a1.bufferlenor0,a1.tablesor{},a1.keyorder,a1)ifnotagthenerror(ah,2)elseifap==_thena1.bufferlen=ag;returntrueelsea1.bufferlen=nil;a1.buffer=nil;returno(_)endend;localfunctionaq(K,ar)localas,at,au=1,1,0;whiletruedoat=k(K,"\n",at,true)ifatandat<arthenas=as+1;au=at;at=at+1elsebreakendend;return"line "..as..", column "..ar-auend;localfunctionav(K,aw,ar)returnnil,l(K)+1,"unterminated "..aw.." at "..aq(K,ar)end;localfunctionax(K,at)whiletruedoat=k(K,"%S",at)ifnotatthenreturnnilend;localay=h(K,at,at+1)ifay=="\239\187"andh(K,at+2,at+2)=="\191"thenat=at+3elseifay=="//"thenat=k(K,"[\n\r]",at+2)ifnotatthenreturnnilendelseifay=="/*"thenat=k(K,"*/",at+2)ifnotatthenreturnnilend;at=at+2elsereturnatendendend;localaz={["\""]="\"",["\\"]="\\",["/"]="/",["b"]="\b",["f"]="\f",["n"]="\n",["r"]="\r",["t"]="\t"}localfunctionaA(C)ifC<0thenreturnnilelseifC<=0x007fthenreturnj(C)elseifC<=0x07ffthenreturnj(0xc0+d(C/0x40),0x80+d(C)%0x40)elseifC<=0xffffthenreturnj(0xe0+d(C/0x1000),0x80+d(C/0x40)%0x40,0x80+d(C)%0x40)elseifC<=0x10ffffthenreturnj(0xf0+d(C/0x40000),0x80+d(C/0x1000)%0x40,0x80+d(C/0x40)%0x40,0x80+d(C)%0x40)elsereturnnilendend;localfunctionaB(K,at)localaC=at+1;local_,v={},0;whiletruedolocalaD=k(K,"[\"\\]",aC)if not aD then return av(K,"string",at)end;if aD>aC then v=v+1;_[v]=h(K,aC,aD-1)end;if h(K,aD,aD)=="\""thenaC=aD+1;breakelselocalaE=h(K,aD+1,aD+1)localC;ifaE=="u"thenC=tonumber(h(K,aD+2,aD+5),16)ifCthenlocalaF;if0xD800<=CandC<=0xDBffthenifh(K,aD+6,aD+7)=="\\u"thenaF=tonumber(h(K,aD+8,aD+11),16)ifaFand0xDC00<=aFandaF<=0xDFFFthenC=(C-0xD800)*0x400+aF-0xDC00+0x10000elseaF=nilendendend;C=CandaA(C)ifCthenifaFthenaC=aD+12elseaC=aD+6endendendend;ifnotCthenC=az[aE]oraE;aC=aD+2end;v=v+1;_[v]=Cendend;ifv==1thenreturn_[1],aCelseifv>1thenreturno(_),aCelsereturn"",aCendend;localaG;localfunctionaH(aw,aI,K,aJ,aK,aL,aM)localaN=l(K)localt,v={},0;localat=aJ+1;ifaw=='object'thensetmetatable(t,aL)elsesetmetatable(t,aM)end;whiletruedoat=ax(K,at)ifnotatthenreturnav(K,aw,aJ)end;localaO=h(K,at,at)ifaO==aIthenreturnt,at+1end;localaP,aQ;aP,at,aQ=aG(K,at,aK,aL,aM)ifaQthenreturnnil,at,aQend;at=ax(K,at)ifnotatthenreturnav(K,aw,aJ)end;aO=h(K,at,at)ifaO==":"thenifaP==nilthenreturnnil,at,"cannot use nil as table index (at "..aq(K,at)..")"end;at=ax(K,at+1)ifnotatthenreturnav(K,aw,aJ)end;localaR;aR,at,aQ=aG(K,at,aK,aL,aM)ifaQthenreturnnil,at,aQend;t[aP]=aR;at=ax(K,at)ifnotatthenreturnav(K,aw,aJ)end;aO=h(K,at,at)elsev=v+1;t[v]=aPend;ifaO==","thenat=at+1endendend;aG=function(K,at,aK,aL,aM)at=ator1;at=ax(K,at)ifnotatthenreturnnil,l(K)+1,"no valid JSON value (reached the end)"end;localaO=h(K,at,at)ifaO=="{"thenreturnaH('object',"}",K,at,aK,aL,aM)elseifaO=="["thenreturnaH('array',"]",K,at,aK,aL,aM)elseifaO=="\""thenreturnaB(K,at)elselocalaS,aT=k(K,"^%-?[%d%.]+[eE]?[%+%-]?%d*",at)ifaSthenlocalaU=X(h(K,aS,aT))ifaUthenreturnaU,aT+1endend;aS,aT=k(K,"^%a%w*",at)ifaSthenlocalaV=h(K,aS,aT)ifaV=="true"thenreturntrue,aT+1elseifaV=="false"thenreturnfalse,aT+1elseifaV=="null"thenreturnaK,aT+1endend;returnnil,at,"no valid JSON value at "..aq(K,at)endend;localfunctionaW(...)ifselect("#",...)>0thenreturn...elsereturn{__jsontype='object'},{__jsontype='array'}endend;functionp.decode(K,at,aK,...)localaL,aM=aW(...)returnaG(K,at,aK,aL,aM)end;functionp.use_lpeg()localaX=require("lpeg")ifaX.version()=="0.11"thenerror"due to a bug in LPeg 0.11, it cannot be used for JSON matching"end;localaY=aX.match;localaZ,a_,b0=aX.P,aX.S,aX.R;localfunctionb1(K,at,ah,a1)ifnota1.msgthena1.msg=ah.." at "..aq(K,at)a1.pos=atend;returnfalseend;localfunctionb2(ah)returnaX.Cmt(aX.Cc(ah)*aX.Carg(2),b1)end;localb3=aZ"//"*(1-a_"\n\r")^0;localb4=aZ"/*"*(1-aZ"*/")^0*aZ"*/"localb5=(a_" \n\r\t"+aZ"\239\187\191"+b3+b4)^0;localb6=1-a_"\"\\\n\r"localb7=aZ"\\"*aX.C(a_"\"\\/bfnrt"+b2"unsupported escape sequence")/az;localb8=b0("09","af","AF")localfunctionb9(ba,at,bb,bc)bb,bc=tonumber(bb,16),tonumber(bc,16)if0xD800<=bbandbb<=0xDBffand0xDC00<=bcandbc<=0xDFFFthenreturntrue,aA((bb-0xD800)*0x400+bc-0xDC00+0x10000)elsereturnfalseendend;localfunctionbd(be)returnaA(tonumber(be,16))end;localbf=aZ"\\u"*aX.C(b8*b8*b8*b8)localbg=aX.Cmt(bf*bf,b9)+bf/bd;localbh=bg+b7+b6;localbi=aZ"\""*aX.Cs(bh^0)*aZ"\""+b2"unterminated string"localbj=aZ"-"^-1*aZ"0"+b0"19"*b0"09"^0;localbk=aZ"."*b0"09"^0;localbl=a_"eE"*a_"+-"^-1*b0"09"^1;localbm=bj*bk^-1*bl^-1/X;localbn=aZ"true"*aX.Cc(true)+aZ"false"*aX.Cc(false)+aZ"null"*aX.Carg(1)localbo=bm+bi+bn;localbp,bq;localfunctionbr(K,at,aK,a1)localbs,bt;localbu;localbv,bw={},0;repeatbs,bt,bu=aY(bp,K,at,aK,a1)ifnotbuthenbreakend;at=bu;bw=bw+1;bv[bw]=bsuntilbt=='last'returnat,setmetatable(bv,a1.arraymeta)end;localfunctionbx(K,at,aK,a1)localbs,a4,bt;localbu;localbv={}repeata4,bs,bt,bu=aY(bq,K,at,aK,a1)ifnotbuthenbreakend;at=bu;bv[a4]=bsuntilbt=='last'returnat,setmetatable(bv,a1.objectmeta)end;localby=aZ"["*aX.Cmt(aX.Carg(1)*aX.Carg(2),br)*b5*aZ"]"+b2"']' expected"localbz=aZ"{"*aX.Cmt(aX.Carg(1)*aX.Carg(2),bx)*b5*aZ"}"+b2"'}' expected"localbA=b5*by+bz+bo;localbB=bA+b5*b2"value expected"bp=bA*b5*aZ","*aX.Cc'cont'+aX.Cc'last'*aX.Cp()localbC=aX.Cg(b5*bi*b5*aZ":"+b2"colon expected"*bB)bq=bC*b5*aZ","*aX.Cc'cont'+aX.Cc'last'*aX.Cp()localbD=bB*aX.Cp()functionp.decode(K,at,aK,...)locala1={}a1.objectmeta,a1.arraymeta=aW(...)localbs,bE=aY(bD,K,at,aK,a1)ifa1.msgthenreturnnil,a1.pos,a1.msgelsereturnbs,bEendend;p.use_lpeg=function()returnpend;p.using_lpeg=true;returnpend;ifathenpcall(p.use_lpeg)end;returnp