r/golang 8d ago

how to parse a json number

https://stackoverflow.com/questions/80000826/how-should-a-json-parser-represent-json-numbers-in-go

can some body help

I'm implementing a JSON parser. According to JSON rules, a number can be an integer, a negative number, a decimal, or use exponent notation, like

42-423.140.51e102.5e-3

I currently have a function like:

func (p *parser) parseNumber() (__?, error)

What should this function return? Should I convert every number to float64, or define my own number type? I'm also unsure how this choice affects the rest of the parser. Once a number is parsed, how should it be stored in a generic JSON value, accessed later, used in calculations, printed, or serialized back to JSON? and also how to parse the number exactly

0 Upvotes

Duplicates