A
A
ashum2012-04-02 14:21:21
JSON
ashum, 2012-04-02 14:21:21

Need a JSON to TXT parser?

Help, please, experts. You can't handle it on your own.
There is an address with data in JSON format: hostname :8082/erlyvideo/api/streams
Data in this form:

{"streams":[{"client_count":0,"created_at":1333358546,"host":"default","last_dts":1376,"last_dts_at":1333358548,"name":"live1","registrator":true,"ts_delay":959,"type":"live","url":"live1","totalDatarate":[49,48,48],"videoKeyframeFrequency":[53]}]}

We need a script (preferably in bash) that would give the contents of the "client_count" value.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
S
S1ashka, 2012-04-02
@ashum

let me insert my rake like I didn’t mess anything up. well, how to run this rake from the console - you'll figure it out =))
<?php
$string = implode('', file('http://hostname:8082/erlyvideo/api/streams'));
$array=json_decode($string);
echo $array['client_count'];
?>

D
DemiurgeOrion, 2012-04-02
@DemiurgeOrion

Look in the direction of this github.com/micha/jsawk
Then "on the bash" your task will be solved in this way:
curl 'hostname:8082/erlyvideo/api/streams' | jsawk -a 'return this.streams[0].client_count'

J
jov, 2012-04-03
@jov

wget -O - someurl | tr "{},[]" "\n" | grep client_count | cut -d: -f 2 
I'm sorry, I made a typo in the first post, and besides, a habraparser ...

A
ashum, 2012-04-02
@ashum

This is what I look at. Thanks for ".streams[0].", there was a gag in this place. Now one more thing - the answer is displayed in the form [0]. How to remove square brackets?

D
DemiurgeOrion, 2012-04-02
@DemiurgeOrion

Regarding cutting off excess:
curl 'hostname:8082/erlyvideo/api/streams' | jsawk 'return this.streams[0].client_count' | grep -Po --regexp="\d+"

A
Anatoly, 2012-04-02
@taliban

And if you just do this: /"client_count":(\d+?),/?

J
jov, 2012-04-03
@jov

wget -O -someurl | | tr "{},[]" "\n" | grep client_count | cut -d: -f 2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question