0 Replies Latest reply: Mar 1, 2013 2:14 PM by cmatta RSS

    ZFS 7420 script "dump" command does not output valid JSON

    cmatta
      While writing some data collection scripts this week I discovered that there's a reason the scripting guide for the 7420 describes what comes out of the "dump()" command as JSON-like. It's not real JSON. I understand that the scripting system on this array is based on JavaScript ECMA rev3, and JSON showed up in rev5, but it almost seems cruel to output data in a format that no JSON parser will touch. It's so close!

      Anyway, if anyone is interested in a series of regular expressions that seems to "fix" most of the issues with the output so that it validates as JSON this is what I came up with (with a little help from stack overflow).
      in python re:
      json_string = <output from dump(object) command>
      json_string = re.sub(r"{\s*'?(\w)", r'{"\1', json_string)
      json_string = re.sub(r",\s*'?(\w)", r',"\1', json_string)
      json_string = re.sub(r"(\w)'?\s*:", r'\1":', json_string)
      json_string = re.sub(r":\s*'(\w*)'\s*([,}])", r':"\1"\2', json_string)

      Does anyone know if there are any plans to get this to actually output valid JSON? That would be ideal.