×

INDI Library v2.0.7 is Released (01 Apr 2024)

Bi-monthly release with minor bug fixes and improvements

IndiWebManager parsing issue with API

  • Posts: 72
  • Thank you received: 21
Dear Jasem.

I working on apps for my raspberry and meet some issue to parse the reply from the APIs.

Replies are provided between braket "[ ]" and my parsing (With libjson0) failed. From the www.json.org/ it looks not correct to have the [ ] at objet level. The first level is an objet and should be between curled "{ }" only at value level we could use bracket for array information.

If I modified, for exemple, the # Server status from :

@app.get('/api/server/status')
def get_server_status():
status = [ { 'status' : str(isServerRunning()) } ]
json_string = json.dumps(status)
return json_string

to:

@app.get('/api/server/status')
def get_server_status():
status = { 'status' : str(isServerRunning()) }
json_string = json.dumps(status)
return json_string

The parser works fine.

Do I misunderstand the explanation from the Internet site behind? or may I ask you to correct the APIs?

EDIT: But the js script doesn't like it! for me looks quite strange, but I don't understand the js code.

Regards
Philippe
Philippe Besson
Skywatcher HEQ5, Televue 101-IS, Takahashi FS-60CB
Focus Boss II with OptecInc TCF-S focuser and Starlight Instruments HSM20 handy stepper motor
Guiding camera ZWO ASI120MM
Filterwheel OptecInc IFW
Camera not set yet
Switzerland
Last edit: 7 years 8 months ago by Philippe.
7 years 8 months ago #9429

Please Log in or Create an account to join the conversation.

  • Posts: 72
  • Thank you received: 21
I've continued to investigate around the rules on JSON and wasn't able to find clearly that if it is not allowed to have square brackets on top level of message. In the same way I didn't find real approvement of it :-(
Anyway no need to have a lot of discussion around this issue as Indiwebmanager works fine today, could be better don't make changes and I'll wrote a short function to remove the first and last square bracket from the replies to solve my issue with libjson0 library, or use another library (available for RPI).

Any suggestion from the Indi's member?

For information with this library if I understand correctly the usage of it, after initialisation we've to call "struct json_object* json_tokener_parse(const char *str);" function. It seems that function is quite permissive except when the first char is [

Related to my low knowledge, it could be that I don't use it correctly :(

Regards, Philippe
Philippe Besson
Skywatcher HEQ5, Televue 101-IS, Takahashi FS-60CB
Focus Boss II with OptecInc TCF-S focuser and Starlight Instruments HSM20 handy stepper motor
Guiding camera ZWO ASI120MM
Filterwheel OptecInc IFW
Camera not set yet
Switzerland
7 years 8 months ago #9434

Please Log in or Create an account to join the conversation.

Time to create page: 0.400 seconds