<s> from dataset . freeze . format . fjson import JSONSerializer <EOL> class TabsonSerializer ( JSONSerializer ) : <EOL> def wrap ( self , result ) : <EOL> fields = [ ] <EOL> data = [ ] <EOL> if len ( result ) : <EOL> keys = list ( result [ <NUM_LIT:0> ] . keys ( ) ) <EOL> fields = [ { '<STR_LIT:id>' : k } for k in keys ] <EOL> for row in result : <EOL> d = [ row . get ( k ) for k in keys ] <EOL> data . append ( d ) <EOL> result = { <EOL> '<STR_LIT:count>' : len ( data ) , <EOL> '<STR_LIT>' : fields , <EOL> '<STR_LIT:data>' : data <EOL> } <EOL> meta = self . export . get ( '<STR_LIT>' , { } ) <EOL> if meta is not None : <EOL> result [ '<STR_LIT>' ] = meta <EOL> return result </s>
