Skip to content

vishu2222/jsonParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONParserJavaScript

  • 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.

Json parser

  • Input -> JSON string (array or object)
  • output -> parsed javaScript value or null for a bad JSON.

Components

Null parser

input : string
output -> [null, rest of the string] or null

Boolean parser

input : string
output -> [true/false, rest of the string] or null

Number parser

input : string
output-> [number, rest of the string] or null

String parser

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.

Array parser

input : string
output-> [array, rest of the string] or null

Object parser

input : string
output-> [object, rest of the string] or null

References

  1. https://wesleytsai.io/2015/06/13/a-json-parser/#comment-3466547787
  2. https://www.json.org/json-en.html
  3. https://www.ietf.org/rfc/rfc4627.txt
  4. https://www.regular-expressions.info/nonprint.html
  5. https://www.rfc-editor.org/rfc/rfc7159#page-8

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published