@@ -7,6 +7,7 @@ using Observables: @map
77export showtable
88
99const ag_grid_imports = []
10+ const js_max_safe_int = Int128 (2 ^ 53 - 1 )
1011
1112function __init__ ()
1213 version = readchomp (joinpath (@__DIR__ , " .." , " ag-grid.version" ))
@@ -252,32 +253,28 @@ end
252253# directly write JSON instead of allocating temporary dicts etc
253254function table2json (schema, rows, types; requested = nothing )
254255 io = IOBuffer ()
255- print (io, ' [' )
256+ rowwriter = JSON. Writer. CompactContext (io)
257+ JSON. begin_array (rowwriter)
258+ ser = JSON. StandardSerialization ()
256259 for (i, row) in enumerate (rows)
257- if requested == nothing || first (requested) <= i <= last (requested)
258- print (io, ' {' )
259- Tables. eachcolumn (schema, row) do val, ind, name
260- JSON. print (io, name)
261- print (io, ' :' )
262- if val isa Number && isfinite (val)
263- JSON. print (io, val)
264- elseif val === nothing
265- JSON. print (io, repr (nothing ))
266- elseif val === missing
267- JSON. print (io, repr (missing ))
268- else
269- JSON. print (io, sprint (print, val))
270- end
271- print (io, ' ,' )
260+ if requested != nothing && (i < first (requested) || i > last (requested))
261+ continue
262+ end
263+ JSON. delimit (rowwriter)
264+ columnwriter = JSON. Writer. CompactContext (io)
265+ JSON. begin_object (columnwriter)
266+ Tables. eachcolumn (schema, row) do val, ind, name
267+ if val isa Real && isfinite (val) && - js_max_safe_int < trunc (Int128, val) < js_max_safe_int
268+ JSON. show_pair (columnwriter, ser, name, val)
269+ elseif val === nothing || val === missing
270+ JSON. show_pair (columnwriter, ser, name, repr (val))
271+ else
272+ JSON. show_pair (columnwriter, ser, name, sprint (print, val))
272273 end
273- skip (io, - 1 )
274- print (io, ' }' )
275- print (io, ' ,' )
276274 end
275+ JSON. end_object (columnwriter)
277276 end
278- skip (io, - 1 )
279- print (io, ' ]' )
280-
277+ JSON. end_array (rowwriter)
281278 String (take! (io))
282279end
283280end
0 commit comments