Previous Topic Next topic Print topic


JSONVALID Function

Purpose

Checks if a JSON text is valid.

Syntax

JSONVALID(p,l)

Parameters

p
A pointer specifying the address of the JSON text buffer.
l
Specifies the length in bytes of the JSON text buffer.

Description

JSONVALID verifies that the supplied buffer contains a valid JSON text. If it does, it returns zero; otherwise it returns the position of the first invalid character. You can use this result to examine the invalid character and/or replace it with a valid character. Keep in mind that the character you are examining is a UTF8 encoded character. And if you choose to replace it, you must replace it with a UTF8 encoded character(s).

Examples

Assuming p points to the buffer which contains the data shown in the examples below, then this invocation Bytes = jsonvalid(p);

Example 1:

{ "NAME" : [0.0,1,-1,2,3.1,-5.12E123,true,false,null] } will find this object to be valid.

Example 2:

{ NAME: Dave } will find this object to be invalid at the position where N is because a double quote is expected in this position. i.e. NAME must be enclosed in double quotes.

Restrictions

None.

Previous Topic Next topic Print topic