Fork me on GitHub

Morning folks, and happy new year…. I’ve spent my christmas break exploring rewrite-clj. It looks really cool and has helped me to finally understand zippers. Kudos on all the project docs. They’ve been really helpful. I’m wondering how you’d go about determining whether some zloc that has been navigated to is a string. My first thought was to say (string? (zip/node zloc)) but that doesn’t work because my string is a token. Then I found node/value which seems to return the string but is marked as deprecated. I tried following the advice in the deprecation node but both node/child-sexprs and node/children are coming out as nil.


Glad you found the docs helpful. Always looking to improve them. Let us know if anything was amiss/confusing.


Ah I see now value works now.


@cddr sexpr should also work


Yeah but the problem is that sexpr seems to return strings even for map nodes. The bigger picture is that I’m using this to edit a json tree and need to isolate my edits to strings in the rhs position of any maps (i.e. leave the keys alone).


sexpr should not return a string for a map node :)


Mm, maybe I made a mistake. Checking again…


although you're speaking about JSON. rewrite-clj is intended to be used on clojure code... JSON...?


Yeah but it comes with a zipper that works well with a variety of data-types. The ones in core work only seem to work if the entire data-structure is built out of the same collection type


What are you referring to by "it" in "it comes with"?


If there’s something else you’re aware of that’s better for editing JSON trees I’d be pleased to discover alternatives. (it=rewrite-clj)


what does your JSON tree look like? Is that valid Clojure code?


It’s a JSON schema so not clojure code at all


if rewrite-clj accepts JSON then that might be accidental, I would not expect that to work at all


unless you convert it to EDN first


Oh sorry, yeah I convert it to EDN first before piping it into rewrite-clj


ok, yes, that should work 😅 you might also be interested in which is a thin layer over rewrite-clj

👀 1

There have been some ideas floating around to make a more elaborate version of tag that returns :string etc and not only :token, which I think should be a good solution in general. I've been making my own predicates in clj-kondo for this.


@lee We could also do something like :rewrite-clj/namespaced-map and use (derive :rewrite-clj/namespaced-map :rewrite-clj/map) so you can use isa? on it. Looks good to me.


I think this is one of the main missing things in rewrite-clj