Giter VIP home page Giter VIP logo

circe-optics's Introduction

circe-optics

Build Coverage status Gitter Maven Central

This project provides tools for working with JSON values using circe and Monocle. It was included in the main circe repository until the 0.10.0 release, when it was promoted to its own project in order to decouple its releases (and the Scala versions it is cross-published for) from the main circe modules.

Versioning

This library releases at a different cadence than Circe, any apparent relationship between the Circe version numbers and circe-optics version numbers are a coincidence and NOT intentional.
Please use the following table for determining capability with the corresponding Circe versions.

Circe Optics Version Circe Monocle Scala 2.12 Scala 2.13 Scala 3 Scala JVM Scala.JS
0.15.x 0.14.x 3.x
0.14.x 0.14.x 2.x

Contributors and participation

This project supports the Scala code of conduct and we want all of its channels (Gitter, GitHub, etc.) to be welcoming environments for everyone.

Please see the circe contributors' guide for details on how to submit a pull request.

License

circe-optics is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

circe-optics's People

Contributors

andrelfpinto avatar benhutchison avatar greyplane avatar guersam avatar hamnis avatar ingemaradahl avatar jatcwang avatar joan38 avatar julien-truffaut avatar n4to4 avatar paulbrimicombe avatar scala-steward avatar travisbrown avatar travisbrown-stripe avatar zarthross avatar zmccoy avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

circe-optics's Issues

Release 0.11.1 to bring the version in line with main Circe library

I currently have the following in my Gradle build file:

circeVersion = '0.11.1'

// ...

compile "io.circe:circe-core_%%:${circeVersion}"
compile "io.circe:circe-generic_%%:${circeVersion}"
compile "io.circe:circe-parser_%%:${circeVersion}"
compile "io.circe:circe-optics_%%:0.11.0"

because 0.11.1 is not released to Maven.

It would be nice if the version of the optics was always in line with the main Circe library.

Alternatively, if that's not feasible, a note about optics version being different should be provided in the optics documentation which currently simply says circeVersion.

[Question] update and release schedule?

This project has been unmaintained for a long time, especially since one of the crucial dependencies Monocle has been outdated, and its API changes rapidly in the new versions.
If needed, I'm willing to do the necessary work to keep the dependency up to date.

Publish for Scala 2.13.0

Although the main Circe project has (RC) releases for Scala 2.13.0, circe-optics doesn't. Would be nice to have one to try things out and migrate.

Behavior on parse to Option[T] are different between Optics and Core's cursor

problem:
for given JSON { "foo": { "baz": 1 } } and two cursor
json.hcursor.downField("foo").downField("bar").as[Option[String]]
root.foo.bar.as[Option[String]].getOption(json)

first one got Right(None) indicated parse success but got no value as expected.
but Optics got just None, which can only be understood as parse failed i guess.

is this behavior intended? and if i want first behavior but still use JsonPath's convenient syntax is there any way?
thanks

No way to create a Fold to a specific A type without Encoder[A]

Problem

Consider a JSON:

{"foo": {"bar": {"goo": {"car": { /* some complex structure inside */ }}}}}

We need to parse and decode the car object into some model:

class Car( /* some accordingly complex structure inside */ )

We don't care about writing this model back to JSON so we only have implemented a Decoder for it:

implicit val carDecoder: Decoder[Car] = { cursor => ??? /* some custom decoder */ }

Now we're attempting to create a JSON path based optic to access it:

JsonPath.root.foo.bar.goo.car.as[Car] // does not compile: could not find implicit value for parameter encode: io.circe.Encoder[Car]

This line fails to compile since the as method requires both Decoder and Encoder (which makes it different from Json#as for example).

Having an Encoder instance could come in handy if we wanted to set/modify the source JSON with some new or update Car instance. But if we don't need to do it (I bet it is 90% or even 99% cases of what JSON paths are created for), then the Encoder instance is not used somehow and just does not allow us to read our model in this way if the model does not have an encoder.

The same can be applied to JsonTraversalPath and JsonFoldPath.
But the latter case is a bit ridiculous, because JsonFoldPath creates a Fold instance, but still requires an Encoder.
The Fold optic cannot be used for "set" or "modify" operations so that encoder comes completely redundant.

Scala3 support

Would be nice to match the main circe project with Scala3 support in the optics.

Add `path` or `lensePath` to JsonPath

The problem:
Given the following json:

{
  "data:0": [0, 122, [0, [111]]]
}

I wanna get a number 111 which in scala code looks like this

val lens = root.selectDynamic("data:0")(2)(1)(0).int

It would be useful have some method (e.g. path) which takes path (HList or list of strings) and return an element on given path. JS library Rambda already had them
https://ramdajs.com/docs/#path
https://ramdajs.com/docs/#lensPath

So this is rather a question or discussion about whether those functions should be added or not?
Maybe there is an idiomatic Scala solution I don't know about?
/cc: @julien-truffaut @travisbrown

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.