How to output JSON in python so it can be used for Geckoboard's Highcharts plugin

formatting, highcharts, json, python

Solution

Just provide the valid json text. Examples in your question are not valid json. Using Push API:

#!/usr/bin/env python
import json
import urllib2

try:
    r = urllib2.urlopen("https://push.geckoboard.com/v1/send/" + widget_key,
                        json.dumps(nested_dict))
except IOError as e:
    if hasattr(e, 'reason'):
       print "connection error:", e.reason
    elif hasattr(e, 'code'):
       print "http error:", e.code
       print e.read()
    else:
       print "error:", e
else: # success
    assert json.load(r)["success"]

Problem

I feel like there's a reasonably simple solution out there for my problem. I'm doing some data manipulation that at the end point gets printed out in a format for highcharts. Currently I'm pulling the whole set of nested dictionaries apart and printing each part out, but I was hoping there was something like JSON.dumps(dict) where the output was formatted with all keys unquoted. So, in code-ish-stuff: ``` { 'chart': {'backgroundColor': 'Blue', 'borderColor': 'Black', 'renderTo': 'container'}, 'xAxis': { ... }, ... } ``` Outputs to ``` { chart: { backgroundColor: 'Blue', borderColor: 'Black', renderTo: 'container'}, xAxis: { ... }, ... } ``` If I can't do outputting like this is there a good way to interface with HighCharts from python? I haven't really ran across one yet, despite some reasonable Google-Fu. EDIT: I'm working on making this compatible with the Geckoboard - Highcharts plugin where-in I don't get the access to the full ability of javascript for parsing the output. I need to have it already formatted and ready to roll when I send the data out.

Original source

Related problems