Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • 20:39
    scala-steward opened #253
  • Jul 12 09:02
    scala-steward closed #248
  • Jul 12 09:02
    scala-steward commented #248
  • Jul 12 09:02
    scala-steward opened #252
  • Jul 09 12:55
    scala-steward opened #251
  • Jul 09 09:07
    scala-steward opened #250
  • Jul 03 02:34
    scala-steward opened #249
  • Jun 14 05:18
  • Jun 14 05:17
    scala-steward closed #246
  • Jun 14 05:17
    scala-steward commented #246
  • Jun 14 05:17
    scala-steward opened #248
  • Jun 08 16:45
  • Jun 08 16:42
    scala-steward opened #247
  • Jun 01 05:16
  • Jun 01 05:15
    scala-steward opened #246
  • May 28 20:43
  • May 28 20:40
    scala-steward opened #245
  • May 28 10:03
  • May 28 10:00
    scala-steward opened #244
  • May 27 18:02
    anilkumarmyla commented #243
Lucas Satabin
if you can share the jsons on which you noticed the difference I can try to find out
Arnaud Gourlay
Will do :thumbsup:
Arnaud Gourlay
@satabin I have created a repo that shows my issue.
master is 4.x
and branch 3.x is for 3.x
It contains a single test implemented for both version
The test checks that the diff of two strings is containing the expected Remove operation.
The test is green on master and red on 3.x.
The Strings are straight from my employer's CI system, sorry for the size.
Lucas Satabin
ok thanks I will investigate
Arnaud Gourlay
Arnaud Gourlay
Looks like I did some weird copy pasta in there, I'll do a second pass to make everything is fine.
Arnaud Gourlay
The test case is invalid, please no not lose your time with this before I fix it :)
Lucas Satabin
ok :)
Arnaud Gourlay
Been hunting the issue all day, now I suspect it might not be in diffson after all :laughing:
Lucas Satabin
I like this kind of bugs ^^
Arnaud Gourlay
And I just found it, it was a tricky one!
The culprit is actually the code feeding data to the diff logic, this means diffson is perfectly fine.
Garbage in, garbage out!
Thanks a lot for your support and Patience :laughing:
Lucas Satabin
ahah sure :)
Arnaud Gourlay
Hi :wave: this is me again with a question :)
In version 3.x I used to call toString on the JsonPatch instance to get a nice printed JSON representation of the operations.
It worked by turning the JsonPatch into a JSON object and then calling pretty print on it.
However in 4.x this behaviour is gone as the toString is not overridden, so instead I print the object structure which is unexpected.
JsonPatch(List(Replace(Chain(Left(assets), Right(0), Left(key)),"new-val",Some("old-val"))))
I looked for a Show instance but could not find any.
Is it possible to reinstate the previous behaviour?
Or should I do it myself? How then?
Thank you :)
Lucas Satabin
Indeed it's not there, because I decided to not put the (de)serialization things in diffson
however, an instance of Show provided by Jsony could be a nice idea
I will work on something
Lucas Satabin
Currently if you want it, then you just need to go through the Json representation of your patch with patch.asJson.spaces2 in circe for instance
I am looking into how it would make sense to have it in diffson without lifting json (de)serealization into the core
Arnaud Gourlay
Thank you very much for the pointer, I have been able to recreate the desired behaviour :thumbsup:
Lucas Satabin
Happy I could help :)
Zach Cox
Hi - the implementation of JsonMergePatch.Value.apply just returns the toJson value, should it instead use toJson to merge patch the original argument? https://github.com/gnieh/diffson/blob/master/core/src/main/scala/diffson/jsonmergepatch/JsonMergePatch.scala#L35-L38
With diffson 3.1.1 we were using JsonMergePatch(p)(j), upgrading to 4.0.2 we're trying to use JsonMergePatch.Value[Json](p).apply[F](j) but that does not seem to use p to merge patch j, and instead just returns p.
Is there a different way in 4.0.2 to create a merge patch from a json value, and then apply it to another json value?
Zach Cox
I think I answered my own question: use json.as[JsonMergePatch[Json]] to create the merge patch?
Lucas Satabin
if I understand correctly you want to get a JsonMergePatch from as Json object?
I moved stuffs out from the core of diffson in version 4, namely everything that is related to (de)serialization
but you seem to have found it. I tried to reflect that in the README, if it's not clear enough I can try to explain a bit more
Lucas Satabin
Just to make it clear: the Value constructor should only be constructed with non-object Json values. If you build it with an object then it won't work, since it is intended to be used for leaves
a patch for an object should use JsonMergePatch.Object
Khagay Nagdimov
Hi! After calling val diffResults = diff(json1, json2), is there a way to traverse through the diffResults.ops(0).path?
Lucas Satabin
Hi, sorry I missed this message @khagaydv01
if this is still something you need, can you tell me a bit more what you want to do?
Hey, is there a way to ignore deleted field from original case class?
My workflow is to apply patches one after another something like patch[Try](json).flatMap(_.as[Entity].toTry), but this Entity does not contain fieldA anymore, and as a result I get
diffson.PatchException: element fieldA does not exist at path 
    at diffson.jsonpatch.Operation.action(JsonPatch.scala:53)
    at diffson.jsonpatch.Add.action(JsonPatch.scala:81)
    at diffson.jsonpatch.Operation.apply(JsonPatch.scala:32)
    at diffson.jsonpatch.JsonPatch.$anonfun$apply$7(JsonPatch.scala:187)
    at cats.instances.ListInstances$$anon$1.step$1(list.scala:136)
    at cats.instances.ListInstances$$anon$1.$anonfun$foldM$2(list.scala:141)
    at cats.instances.TryInstances$$anon$1.tailRecM(try.scala:57)
    at cats.instances.TryInstances$$anon$1.tailRecM(try.scala:15)
    at cats.instances.ListInstances$$anon$1.foldM(list.scala:141)
    at cats.instances.ListInstances$$anon$1.foldM(list.scala:16)
    at cats.Foldable$Ops.foldM(Foldable.scala:31)
    at cats.Foldable$Ops.foldM$(Foldable.scala:31)
    at cats.Foldable$ToFoldableOps$$anon$5.foldM(Foldable.scala:31)
    at diffson.jsonpatch.JsonPatch.apply(JsonPatch.scala:187)
The prefect solution for me is to completely ignore fieldA, but couldn't figure a clean way so far
Lucas Satabin
I have to check again, but I think it is supposed to be failing according to the RFC
if not, I will fix this
Indeed, RFC requires the removed element to exist for this operation to be valid
what can be done however, is add an extension to the operation, a field named strict for instance, that would allow for a more lenient application of it
Lucas Satabin
Hi! I'm trying to use "org.gnieh:diffson-play-json_2.12:4.0.3"
and have hard times verifying result.
Here is my code
val first =
        | "changeMe": "oldValue",
        | "deleteMe": "deleted"
    val second =
        | "changeMe": "newValue",
        | "addMe": "added"
    val diffs = JsonDiffer.diffJson(actual = first, expected = second)
    diffs.ops should have size 3
    diffs.ops.find(_.isInstanceOf[Remove[JsValue]]).map(remove => remove.path) shouldBe Some("deleteMe")
result is
diffs: JsonPatch(List(Add(Chain(Left(addMe)),"added"), Replace(Chain(Left(changeMe)),"newValue",Some("oldValue")), Remove(Chain(Left(deleteMe)),Some("deleted"))))
I don't follow how to extract result and verify it...
doc says diff lib should produce json and I don't follow to to turn it to json or any other usable structure. Can you help me please?
Lucas Satabin
Hello @serega-upgini sorry I was on holidays and just saw your message
This is the Scala representation of a JSON Patch, if you want to serialize it into actual JSON, you need to import the right library support (in your case import diffson.playJson.DiffsonProtocol._) and then serialize this using the standard Play! Json way
I don't remember what tools Play! exposes for that
It looks like the Play Json object has a method for that. Try val json = Json.toJson(diffs)
if you have the protocol imported then it should give you the Json structure for this patch
Stefano Sgorlon

This example in the README fails to compile:

import scala.util.Try
import cats.implicits._
val json2 = patch[Try](json1)

It complains about a missing implicit.
Would be good to update the README with a working example.

Hey. Is there any way to ignore the order of elements in JsArray? I use diffson-spray-json and try to generate diff between 2 JSONs, but I would like to ignore the difference in the order as I have a field with an array of numbers and I don't care about order inside, but I'm getting replace operation like this: Replace(Chain(Left(versions)),[4,2,3,1],Some([1,2,3,4]))