Page 1 of 1

check object json

Posted: Monday 02 April 2018 22:03
by david31
Hello

I would if it's possible to test if an object exist on response json

Code: Select all

{
"tickets": [],
"links": [],
"disruptions": [],
"notes": [],
"feed_publishers": [],
"context": {
"timezone": "Europe/Paris",
"current_datetime": "20180402T213237"
},
"error": {
"message": "no solution found for this journey",
"id": "no_solution"
},
"exceptions": []
}
When no data, the field error exist
when data exist, the field error don't exist

i have test

Code: Select all

jsonLocation.error.id == "no_solution"
but i have

Code: Select all

[string "commandArray = {} ..."]:43: attempt to index field 'error' (a nil value)
when the field don't exist

Re: check object json

Posted: Wednesday 04 April 2018 9:02
by david31
i have found this and it work fine

Code: Select all

string.match(jsondevices, "error", 1)