Reformat json does not validate

Issue #5 resolved
Former user created an issue

Reformat json function claims to validate json provided but it appears to fail in (at least) the following cases: ("input"=>"output") "404 error blahblah..." => "404" ""uh oh" 404 error" => ""uh oh"" others have correct behavior: "error 404" => {error code 1} This is using the current source, freshly downloaded from this page

Comments (5)

  1. James Powell repo owner

    Sorry, I don't understand what your test case notation means. What is the JSON that fails?

  2. James Powell repo owner

    I think I'm being confused by your extra quotes about your test cases. You mean:

    • 404 error blahblah => 404
    • "uh oh" 404 error" => "uh oh"
    • error 404 => {error code 1}

    This is because I am defining the JSON input as a JSON Value that is possibly followed by other text. This is in analogy to the unflatten-from-string functions, where there is a "rest of string". This supports use cases like the streaming of multiple JSON Values, or JSON headers on the front of binary data. Also, I am acting on JSON Values, not restricted to JSON Objects/Arrays. So, all those inputs are handled correctly, as they are indeed the leading JSON Values (if present).

    We might want a separate validating function that allows one to specify the the input string should be a single Object/Array with no following characters other than whitespace.

  3. D Smith

    Sorry about that, it didn't preserve the newlines in the submission so it ended up unnecessarily hard to read. That having been said, yes, you correctly interpreted (except line two has no final quote, just the quotes around "uh oh").

    Anyway, that makes more sense now. I do think a more strict validation/reformat function does make sense though, but its not critical -- More important I think is to document that behavior in the help for the reformat json function, as the current terminology makes it sound like its going to validate the whole input string as JSON.

  4. D Smith

    Just to add on what I'm using it for: all of my devices use json for configuration and its exposed through a web interface. As a first pass at a group configuration editor, I'm simply fetching the data and displaying it after pretty printing (and in another view, breaking it down into its constituent parts hence issue #4). In some cases (especially since I'm using fake data) my devices respond with http errors, which I want to display as-is without formatting. Then when I hit the 'push to devices' button I want to validate that what I'm sending is either an object or an array, and then maybe pop up a 'confirm' dialog if it isn't. The other function you provided in issue #4 should work great for that, though.

  5. Log in to comment