From 534ca4633ee5213fa7ae4171620cb38c7146da88 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Thu, 3 Apr 2014 17:09:58 +0200 Subject: [PATCH] pyterm: distinguish between int and string in JSON sending --- dist/tools/pyterm/pyterm.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dist/tools/pyterm/pyterm.py b/dist/tools/pyterm/pyterm.py index 840023411f..bc8115ce16 100755 --- a/dist/tools/pyterm/pyterm.py +++ b/dist/tools/pyterm/pyterm.py @@ -234,10 +234,18 @@ class SerCmd(cmd.Cmd): for j in self.json_regs: m = self.json_regs[j].search(output) if m: - json_obj = '{"id":%d, ' % int(j) + try: + json_obj = '{"jid":%d, ' % int(j) + except ValueError: + sys.stderr.write("Invalid JID: %s\n" % j) + break json_obj += '"raw":"%s", ' % output + json_obj += '"date":%s, ' % int(time.time()*1000) for g in m.groupdict(): - json_obj += '"%s":"%s", ' % (g, m.groupdict()[g]) + try: + json_obj += '"%s":%d, ' % (g, int(m.groupdict()[g])) + except ValueError: + json_obj += '"%s":"%s", ' % (g, m.groupdict()[g]) # eliminate the superfluous last ", " json_obj = json_obj[:-2]