1 """
2 Writing tables in JSON.
3
4 We use python's built-in json engine to write an -- as yet -- ad-hoc json
5 format that essentially looks like this:
6
7 {
8 "contains": "table",
9 "columns": { (column metadata more or less as in VOTable) }
10 "data": { (rows as tuples) }
11 ("warnings": [...])
12 }
13
14 No streaming at all is forseen for this format at this point.
15 """
16
17
18
19
20
21
22
23 import json
24
25 from gavo import base
26 from gavo import rsc
27 from gavo.formats import common
28
29
46
47
49 """returns a sequence of VOTable-like column description dictionaries.
50 """
51 res = []
52 for annCol in serManager:
53 res.append(annCol.annotations.copy())
54 res[-1].pop("displayHint", None)
55 res[-1].pop("winningFactory", None)
56 res[-1].pop("nullvalue", None)
57 res[-1].pop("note", None)
58 return res
59
60
75
76
92
93
95 """writes table to the target in ad-hoc JSON.
96 """
97 jsonPayload = _getJSONStructure(table, acquireSamples)
98 return json.dump(jsonPayload, target, encoding="utf-8")
99
100
101
102
103 common.registerDataWriter("json", writeTableAsJSON, "application/json",
104 "JSON", ".json")
105