GithubHelp home page GithubHelp logo

Comments (2)

valderman avatar valderman commented on June 26, 2024

I think this would be doable for 90% of cases without too much work. The last 10% would be significantly harder. Consider the following examples:

[foo]
bar = 123
foo = {bar = 123}
foo.bar = 123

All of these map to {"foo": {"bar": 123}} in JSON notation. While the two first cases are easy enough to handle - just annotate foo with the type of dictionary it corresponds to - the third one is a problem. Handling cases like this would require replacing the current simple pretty-printing algorithm with some slow and convoluted hackery, and the annotations to support it would be pretty invasive to boot.

Would a best effort solution, which does the right thing as long as you only use the first two forms but converts the third form into the first during a roundtrip, still be useful?

from 4koma.

henrikje avatar henrikje commented on June 26, 2024

In my case, I have an end-user editable configuration file which may include custom formatting and comments. The file is read in full and decoded to data classes on startup. In some cases I want to persist changes to the configuration. Typicaly, I have one or a few specific value(s) that I want to change programmatically. The rest of the file should not be changed (i.e. preserving custom white space and comments).

The value (X) I want to change may be at different levels, such as:

a = "X"
[a]
b.c = "X"
[a]
b = [ "X", "y", "z" ]
[a]
b = [ { c = "X", d = "y" }, { e = "z" } ]

As hinted at earlier, if it is simpler, for my use case it would be fine to say something like:

tomlMapper.encodeInline(tomlFilePath, "a.b.c", newValue)

In this case, the full file would not be decoded. Instead, it would be parsed only enough to identify the "bounds" of the existing value for that key in the file, and then replace that part of the file with the new value.

from 4koma.

Related Issues (20)

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.