Let's define a JSON datum to be any of - nil - false or true - any kind of number - any kind of string - any kind of sequence (other than a string) whose elements are JSON data - any kind of dictionary whose keys are some kind of string and whose elements are JSON data. We start with the observation that it is dead simple to write Smalltalk code to print out a JSON datum in strict JSON format, as long as you don't get fancy. (Like NeoJSON does.) My Smalltalk code for this is 106 lines in methods, and by far the hardest thing was escaping the right characters the right way in strings. Everything else is simple and obvious. So if the existing JSON support in your language doesn't print what you want, it might well be easier to write your own than to find and understand the relevant documentation. We continue with the observation that if you want to test code that generates JSON data to see if you are getting the JSON data you're expecting, it's even easier to write #asJsonEquals:, where x asJsonEquals: y is true iff and only if x and y are both JSON data and would print the same way up to permutation of key:value pairs in JSON objects. My code is 34 lines of methods. Given that, which you want in your JSON toolkit anyway, [(code for testing) asJsonEquals: 'what you expect' readStream nextJson] assert is not hard to do. Test case that generate structured data should generally NOT compare against strings. This also applies to XML (where attribute order needs to be canonicalised or ignored). On Sat, 11 Apr 2026 at 10:53, Richard O'Keefe <raoknz@gmail.com> wrote:
In Json, arbitrary anounts of white space can appear between tokens, including line feed. If this is âpainfulâ for your tests, then itâs unlikely to be the only thing that is. If you are comparing JSON irms *as* JSON, then linefeeds wonât matter . If you are comparing JSON items as strings, there are so many ways that different strrings can represent the same value -infinitely many, in fact - that linefeeds are the least of your worries.
What are you actually doing in your tests?
On Fri, 10 Apr 2026 at 10:55â¯PM, stephane ducasse via Pharo-users < pharo-users@lists.pharo.org> wrote:
Hi
I would like to know if there is a way to generate JSON without lf?
toJsonStringPretty: is generating lf and this is painful for tests.
S.