Coder Social home page Coder Social logo

clj-json-patch's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

clj-json-patch's Issues

Clojurescript support?

Hi, is there any plans for releasing a clojurescript version of this library?
I'm actually interested of using with mori from plain javascript. Any suggestion?

cheers.

Adding to object within an array duplicates the array element

This is similar to #4

(def obj {"array" [{"id" "hello"}]})

(def ops [{"op" "add" "path" "/array/0/foo" "value" "bar"}])

(patch/patch obj ops)

actual:

=> {"array" [{"id" "hello", "foo" "bar"} {"id" "hello"}]}

expected:

=> {"array" [{"id" "hello", "foo" "bar"}]}

No support for booleans

I'm currently unable to apply patches on booleans. I assume this is a valid use-case as I see it done in other json-patch examples.

repl=> (clj-json-patch.core/patch {"enabled" false} [{"op" "replace", "path" "/enabled", "value" true}])

Exception Can't replace a value that does not exist at '/enabled'.  clj-json-patch.util/replace-patch-value (util.clj:165)

unable to patch nested objects

Example:

Consider these 2 objects:

(def obj1 {"nested" {"foo" "bar"}})

(def obj2 {"nested" {"foo" "bar"
                     "zot" "baz"}})

diff works as expected:

(diff obj1 obj2)
=> [{"value" "baz", "op" "add", "path" "/nested/zot"}]

But patch throws an exception:

(patch obj1 (diff obj1 obj2))
Exception Unable to set value at '/nested/zot'. Consider adding a more explicit data structure as a child of an existing object.  clj-json-patch.util/add-patch-value (util.clj:131)

remove of item nested in array element duplicates the element

Example:

(def obj {"array" [{"name" "item1" "foo" "bar"}
                   {"name" "item2" "foo" "bar"}]})

(def ops [{"op" "remove" "path" "/array/0/foo"}])

(clojure.pprint/pprint (patch obj ops))

Actual:

{"array"
 [{"name" "item1"}
  {"name" "item1" "foo" "bar"}
  {"name" "item2" "foo" "bar"}]}

Expected:

{"array"
 [{"name" "item1"}
  {"name" "item2", "foo" "bar"}]}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.