Answer the question
In order to leave comments, you need to log in
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]}]}
Answer the question
In order to leave comments, you need to log in
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'];
?>
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'
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 ...
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?
Regarding cutting off excess:
curl 'hostname:8082/erlyvideo/api/streams' | jsawk 'return this.streams[0].client_count' | grep -Po --regexp="\d+"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question