Skip to main content

Timeline for Parsing JSON in one go

Current License: CC BY-SA 4.0

41 events
when toggle format what by license comment
S Feb 19, 2019 at 21:48 history suggested Glorfindel CC BY-SA 4.0
broken images fixed (click 'rendered output' to see the difference); for more info, see https://gist.github.com/Glorfindel83/9d954d34385d2ac2597bbe864466259f
Feb 19, 2019 at 21:06 review Suggested edits
S Feb 19, 2019 at 21:48
Apr 13, 2017 at 12:40 history edited CommunityBot
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Apr 12, 2017 at 7:31 history edited CommunityBot
replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Mar 16, 2017 at 16:38 history edited CommunityBot
replaced http://meta.codereview.stackexchange.com/ with https://codereview.meta.stackexchange.com/
Mar 13, 2016 at 9:26 comment added Lin Ma Thanks Tersosauros, mark your answer as reply and grant 50 more points, appreciate all the help so far. :) We can continue to discuss here (codereview.stackexchange.com/questions/122534/…) about whether using one state variable is good as well to make code simpler. Your advice is highly appreciated. :)
Mar 13, 2016 at 9:25 history bounty ended Lin Ma
Mar 13, 2016 at 9:25 vote accept Lin Ma
Mar 13, 2016 at 6:45 comment added Tersosauros As I've said, stringIgnore is a "peer" to your wordBeautify function's noMeaningChars string. It is just used to strip characters from the ENDS of strings. To quote a previous comment I made: "The stringIgnore, as with noMeaningChars inside wordBeautify in your original code, only removes those characters from the start and end of the STRING. This is the same behaviour as wordBeautify, but implemented using strip() as I recommended in my comment on your question". So "Hello, State Machine" stays "Hello, State Machine", but ",Hello State Machine" doesn't.
Mar 13, 2016 at 0:30 comment added Lin Ma BTW, I will mark this thread as answered when stringIgnore issue is clear and we can continue to discuss on the new thread using one state for state machine implementation. :)
Mar 13, 2016 at 0:29 comment added Lin Ma Thanks Tersosauros for the clarification, the last question on this thread is about the stringIgnore you are using, currently you are assigning values of '{,:}' to stringIgnore, I think it may have issues, since if for a string (either key or value), if it is "Hello, State Machine", since comma is in stringIgnore, you will change the string to "Hello State Machine", which is not accurate. I may mis-understand your code, so please feel free to correct me. :)
Mar 12, 2016 at 22:54 comment added Tersosauros Ahh I see, well if you're willing to exclude empty keys as a possibility then yes, using your way of if mostRecentKey would make some sense - as it is more readable!
Mar 12, 2016 at 20:29 comment added Lin Ma Thanks Tersosauros , I tried if mostRecentKey is an empty string, your codeif not mostRecentKey is None will be True, but my code if mostRecentKey will be false, I think empty key cannot be used as valid result. And it is why I am asking. Your advice is highly appreciated. Vote up as well. :)
Mar 12, 2016 at 0:37 comment added Tersosauros As I have said about if not mostRecentKey is None: "you could use if mostRecentKey - however that will mean any mostRecentKey value that evaluates to false cannot be a key name. Using if not mostRecentKey is None gets around this by being more explicit." So, again it's about an explicit coding style.
Mar 12, 2016 at 0:34 comment added Tersosauros Yes, the stringIgnore is a "peer" to your wordBeautify, exactly The reason my code has a NOP and your's didn't - is because your code had the two lines: if str1[i]==':': and elif str1[i]==',' or str1[i]=='}':. Therefore (since you have no else block after those) your code ignores whitespace, etc without a variable. Obviously for a state machine, we need a variable for this - so that it can be made explicit.
Mar 12, 2016 at 0:23 comment added Lin Ma And Tersosauros, for sure, I will definitely mark it as an answer after the above two small issues are resolved. :)
Mar 12, 2016 at 0:23 comment added Lin Ma Thanks Tersosauros , appreciate clarify your code is peer to my wordBeautify part of code, and my question actually is, why you are using two sets of characters stringIgnore and NOP? My wordBeautify only use one set of no-meaning characters. Thanks. :)
Mar 12, 2016 at 0:21 comment added Lin Ma Thanks Tersosauros, my last question is if I just write if mostRecentKey to replace if not mostRecentKey is None, if not, could you show me an example why? Thanks.
Mar 11, 2016 at 12:03 comment added Tersosauros @ LinMa Voted up. If you are done with this question (and moving on to your new one then please accept an answer on this question, as this is how the StackExchange network operates. I will take a look at your new question. Thanks.
Mar 11, 2016 at 12:03 comment added Tersosauros The stringIgnore, as with noMeaningChars inside wordBeautify in your original code, only removes those characters from the start and end of the STRING. This is the same behaviour as wordBeautify, but implemented using strip() as I recommended in my comment on your question.
Mar 11, 2016 at 4:33 comment added Lin Ma BTW, Tersosauros, I post my new vesion of code here, and your advice is highly appreciated, thanks. codereview.stackexchange.com/questions/122534/…
Mar 11, 2016 at 3:48 comment added Lin Ma And Tersosauros , another question is still about stringIgnore, here is your code,stringIgnore='{,:}', my confusion is it seems you think such characters could be ignored in STRING {,,,:,}? Why? An example is appreciated. I think they are valid characters inside a STRING, please feel free to correct me. :)
Mar 11, 2016 at 3:46 comment added Lin Ma Thanks Tersosauros, vote up. :) BTW, I edit my original post and re-write a new version of pseudo code (I do not handle some corner cases) based on your guidance of state machine, one point I think your code is a bit confusing to me is using two state variables -- newState and state, and I rewrite code using only one state variable, I am not 100% confident if my code is correct logic and your advice is highly appreciated. :)
Mar 11, 2016 at 2:50 comment added Tersosauros Ahh, I see. If NOP didn't have the whitespace characters (\t, \r, \n, and ' ' (space)) then each of these characters would need their own state in the state machine. Putting them in NOP means we don't need more states (since they get ignored, as a NO-OP (NOP).
Mar 11, 2016 at 2:46 comment added Lin Ma Thanks Tersosauros, vote up. My question is why NOP and stringIgnore NOP=" {\t}\r\n" and stringIgnore='{,:}' have different values?
Mar 11, 2016 at 2:43 comment added Tersosauros @LinMa As I said stringIgnore is just the same as noMeaningChars. The characters in NOP are for parsing the JSON. Where-as, the stringIgnore/noMeaningChars is used when processing STRING as you say.
Mar 9, 2016 at 7:56 comment added Lin Ma @Tersosauros, for the mostRecentKey question, let me rephrase, my question is, what is the issue do you think if I just write if mostRecentKey to replace if not mostRecentKey is None? Thanks.
Mar 9, 2016 at 7:53 comment added Lin Ma @Tersosauros, nice catch and vote up. Wondering why you need to use stringIgnore, other than using the same set of characters inNOP for STRING? Anything special for STRING? Thanks.
Mar 8, 2016 at 19:57 comment added Tersosauros The stringIgnore variable is just a different name for the noMeaningChars one from the original code. It's just the characters that have no meaning in the input of a STRING. It ignores them the same as wordBeautify did - but as part of one big loop (so it can all be done "in one go").
Mar 8, 2016 at 19:53 comment added Tersosauros I'm not sure what you mean about the mostRecentKey "problem"? Obviously you don't want a key of None in the result. Right? I was talking about the idea you mentioned of using if mostRecentKey instead. Also as @oliverpoolsaid, his syntax is probably more readable!
Mar 8, 2016 at 5:59 comment added Lin Ma BTW, Tersosauros , did a lot of debugging and learning from your code today and confused by the logical meaning of stringIgnore='{,:}', and why do you ignore such two characters? Appreciate for clarification and example. :)
Mar 7, 2016 at 17:44 comment added Lin Ma BTW, Tersosauros, another quick question is, what is the logical meaning of READY status? I think it means we have completed either STRING, NUMBER, COLON, COMMA status and READY is a status means begin to enter either of such 4 status? Thanks.
Mar 7, 2016 at 17:31 comment added Lin Ma Thanks Tersosauros, nice catch and vote up, but how your solution resolve the problem mostRecentKey has some value, but not related to a key? I see you just check for null or not by if not mostRecentKey is None? -- “that will mean any ·mostRecentKey· value that evaluates to false cannot be a key name”
Mar 7, 2016 at 13:35 comment added oliverpool @Tersosauros maybe if mostRecentKey is not None is easier to read (and understand)
Mar 7, 2016 at 8:42 comment added Tersosauros if the state is STRING it means we have already triggered the transition from the READY state into STRING (by finding a ") - so it means we are in the middle. Yes, you could use if mostRecentKey - however that will mean any mostRecentKey value that evaluates to false cannot be a key name. Using if not mostRecentKey is None gets around this by being more explicit.
Mar 7, 2016 at 8:08 comment added Lin Ma Also for statement, if not mostRecentKey is None, why not just write as if mostRecentKey? I think you just need to check if mostRecentKey is None or not? Thanks.
Mar 7, 2016 at 8:07 comment added Lin Ma Thanks Tersosauros, in your code, state is STRING, does it mean at the begin of a reading a string, or in the middle of reading a string? Thanks.
Mar 7, 2016 at 7:58 comment added Tersosauros Thank you! (1) The accumulator is where stream data (characters) are stored after reading and before being put into the result. (2) Yes, a STRING is always "quoted", where-as a NUMBER is never like that. a NUMBER also can only have the characters 0123456789. - where-as a string can have anything (except for a quote). Yes, search is basically a dictionary of the _trigger) characters.
Mar 7, 2016 at 7:56 comment added Lin Ma Another quick question is, for your data structure search, it is actually a dictionary, correct? For example, key is ", value is STRING, key is :, and value is COLON, correct? :)
Mar 7, 2016 at 7:53 comment added Lin Ma Very nice post, Tersosauros! Vote up. Two quick questions, (1) what are the logical meaning of "accumulator"? And (2) you distinguish between STRING and NUMBER because for NUMBER it does not have to be quoted by "? Thanks. :)
Mar 7, 2016 at 7:13 history answered Tersosauros CC BY-SA 3.0