Fix public API error checking

:Release Notes:
Check what is passed by the client code carefully to avoid
unexpected crashes.
Fix memory leaks in case of invalid operations on array and object.

:Detailed Notes:
Currently, assert() was used to check that arguments are in valid
ranges. But those asserts are compiled out in release builds and
thus ineffective for client applications. The library should use
explicit checks and error codes (or exceptions in C++) to inform
about incorrect arguments.

:Testing Performed:
Build succeeded.

:QA Notes:

:Issues Addressed:
[GF-8147] libpbnjson: Check and fix type information in all public API

Open-webOS-DCO-1.0-Signed-off-by: Anatolii Sakhnik <anatolii.sakhnik@lge.com>

Change-Id: Ie40055e4c825fa8838a01ddb3d055126b9fb6811
Reviewed-on: https://g2g.palm.com/2870
Reviewed-by: Build Verification
Reviewed-by: Anatolii Sakhnik <anatolii.sakhnik@lge.com>
Tested-by: Anatolii Sakhnik <anatolii.sakhnik@lge.com>
Reviewed-by: Keith Derrick <keith.derrick@lge.com>
Reviewed-by: Alekseyev Oleksandr <alekseyev.oleksandr@lge.com>