- Joined
- Feb 3, 2013
This doesn't work. You can't just remove all whitespace from the JSON, whitespace inside a string is data that has to be preserved. I'd rethink the whole whitespace-removing thing, as long as you have to keep track of whether you're in a string or not (including watching out for escaped end quotes), you might as well go all the way and just ignore whitespace "live" during parsing when you're keeping track of all that stuff anyway.While we're on the topic of recursion, who wants to rate my json to xml converter?
Answer the age-old question: is this NIGGERLICIOUS, or DIVINE INTELECT?
Why are you
fseek
ing around with file pointers? I think it'd be better to just read the input file (or at least the chunk of it you're currently working on) into memory and use actual pointers.Also:
C:
FILE* new_json = fopen("./temp.json", "w");
// ...
fclose(new_json);
// ...
FILE* json = fopen("./temp.json", "r");
EDIT: one other thing, the JSON definition of "whitespace" isn't exactly the same as the
isspace
definition either.By default,
isspace
counts \f
and \v
as whitespace, but JSON doesn't.https://en.cppreference.com/w/cpp/string/byte/isspace
https://www.rfc-editor.org/rfc/rfc8259.txt
(EDIT 2: also, having functions called "array" and "string" is probably asking for trouble if you ever plan to bring C++ into the mix and someone using's the std namespace.. I don't know what "wins" in clashes like that and I refuse to find out)
Last edited: