Stripping timestamp from Json int
Question: In a third-party script, it's meant to spit out Json for me to decode but
instead prepends a timestamp:

    
    
    2015-03-28T16:32:41.875199+00:00 {"1": {"Power (kW)": "0.301", "Energy Imported (kWh)": "62.281"...}}
    

All of this is in one big integer. I've tried to split this based on the
space/whitespace contained before the first curly bracket but can simply not
do it. I'd really appreciate some pointers - I'm aware my questions here are
very basic, and apparently I'm going to be blocked soon unless I improve, so
please don't shoot me for asking another simple one!

Updated 31/3/2015 for @Alex.

I realise it may seem impossible but assure you that it returns a datatype of
int. You may not believe it, but you'll have to, and [check the guy's code
here](https://github.com/edrabbit/neurio). This is what I've used to call the
script:

    
    
    get_power=os.system("python /fetch_neurio.py --ip 172.16.0.8 --format json --type sensor")
    thedata = get_power
    print type(thedata)
    

If you find that too unbelievable then look at the code of fetch_neurio
yourself. If you're struggling to help a cretin like me, then no worries. I
just came here to ask for help.

Thanks


Answer: No idea what you mean by "one big `int`" in the text **and** subject since
pretty clearly the data is a **string** , not an integer. I'm going to answer
on the assumption that your repeated use of `int` is just a weird repeated
typo and you meant "string" instead.

Given

    
    
    data = '2015-03-28T16:32:41.875199+00:00 {"1": {"Power (kW)": "0.301", "Energy Imported (kWh)": "62.281"}}'
    

(removing the `...` to make the JSON part syntactically valid),

    
    
    import json
    
    timestamp, jsondata = data.split(None, 1)
    pythondata = json.loads(jsondata)
    

...yep, it **is** as simple as this!-)

"Splitting on `None`" means to split on sequences of 1+ whitespace characters
(in case that blank-looking thing might be a tab or whatever, we don't
care:-). The second optional argument, here `1`, to the split method, means to
do just one split (on the very first sequence of whitespace) -- thus producing
two pieces that we assign correspondingly to two variables.

There are of course other possibilities, for example using regular
expressions, if the anomalies in `data` are worse than you have communicated
so far (i.e, more than just a pre-pended, whitespace separated timestamp), but
based on what you **have** communicated, this simplistic approach should
suffice.

