rbonghi / jetson_stats

📊 Simple package for monitoring and control your NVIDIA Jetson [Orin, Xavier, Nano, TX] series
https://rnext.it/jetson_stats
GNU Affero General Public License v3.0
2.17k stars 264 forks source link

`jetson.stats` is not a valid JSON string #398

Closed sheldonmaschmeyer closed 1 year ago

sheldonmaschmeyer commented 1 year ago

Describe the bug

The jetson.stats is almost a valid JSON string but I need to make tweaks to the string for it to pass validation.

The following is done in JavaScript.

jetsonStats = jetsonStats.replace(/'/g, '"');
jetsonStats = jetsonStats.replace(/: datetime/g, ': "datetime');
jetsonStats = jetsonStats.replace(/\),/g, ')",');
JSON.parse(jetsonStats) // Success

To Reproduce

Steps to reproduce the behavior:

  1. jetson = jtop()
    jetson.start()
    print(jetson.stats)
    jetson.close()
  2. Copy string to an online validator such as https://jsonlint.com/ Notice it does not pass.

  3. Pass string to Node.JS

    jetsonStats = jetsonStats.replace(/'/g, '"');
    jetsonStats = jetsonStats.replace(/: datetime/g, ': "datetime');
    jetsonStats = jetsonStats.replace(/\),/g, ')",');
    console.debug(jetsonStats)
    JSON.parse(jetsonStats)
  4. Notice it now passes the online validator https://jsonlint.com/

Board

Ubuntu 18.04 jetson-stats==4.1.5

sheldonmaschmeyer commented 1 year ago

Found article https://www.influxdata.com/blog/nvidia-jetson-series-part-1-jetson-stats/

rbonghi commented 1 year ago

There is now a new function

jetson.json()

https://rnext.it/jetson_stats/reference/jtop.html#jtop.jtop.json

sheldonmaschmeyer commented 1 year ago

Thanks :+1: