- JSON strings have values that need to be parsed for a language to interpret it. Various types like numbers strings, boolean, array and object are encoded inthe JSON string.
- JSON structure is described at json.org and in detail at link.
- Input -> JSON string (array or object)
- output -> parsed javaScript value or null for a bad JSON.
input : string
output -> [null, rest of the string] or null
input : string
output -> [true/false, rest of the string] or null
input : string
output-> [number, rest of the string] or null
input : string
output-> [sting, rest of the string] or null
Note: when it comes to an input string containing '\'. Reading the input from a file has a different behaviour compared to assigning the input with in the program. For example if a test file contains the input string "abc\nabc" the back-slash is read as a seperate char '\\' (length = 1 ) and 'n' (length = 1 ) as seperate. But within the pogram if the exact string is assigned to input i.e, input = '"abc\nabc"', '\n' (length = 1)is read as a single character.
Also, when reading a string from a file, 'abc\ndef' does not have control char but
"abc
def"
has a control char.
Thus this program works only when JSON string is read from a file rather than being passed directly with in the program through assignment.
input : string
output-> [array, rest of the string] or null
input : string
output-> [object, rest of the string] or null