Git Product home page Git Product logo

Comments (6)

kislyuk avatar kislyuk commented on May 31, 2024

Thanks for reporting - unfortunately this is tricky since after round-tripping through JSON, there is no metadata on what kind of block the original text was. We could probably configure PyYAML to write all multiline strings as literal blocks or folded blocks, but I'm not sure if that's always the best thing to do, or what else to do to improve this.

from yq.

varac avatar varac commented on May 31, 2024

I see two issues:

  1. Added newlines between the 3 lines in the example, completely breaking/altering the value
  2. yq should preserve the type, and not replace a literal block or folded block with a quoted multiline string.

Both should be fixed imho but I guess the first one is easier.. ?

Is there any corresponding issue at the PyYAML that would help yq with this ?

from yq.

kislyuk avatar kislyuk commented on May 31, 2024

The first observation that you make is not an issue. The two constructs in the description are equivalent in YAML. See the YAML spec and https://yaml-multiline.info/ for a thorough explanation of this.

As I mentioned in my previous comment, there is no metadata preserved in JSON on what kind of block the original string was. As such there is no obvious way to solve the second issue that you mention under the design constraints of yq.

from yq.

varac avatar varac commented on May 31, 2024

Awesome, thx !!

from yq.

varac avatar varac commented on May 31, 2024

Is this the desired behaviour ?

This looks pretty well:

❯ cat y
some:
  file: |
    hello world
    line1
    line2

❯ yq -Y . < y
some:
  file: |
    hello world
    line1
    line2

❯ yq -Y .some < y
file: |
  hello world
  line1
  line2

But when I query the exact key, the literal block is not presered anymore:

❯ yq -Y .some.file < y
'hello world

  line1

  line2

  '

from yq.

kislyuk avatar kislyuk commented on May 31, 2024

Yes. You don't need -Y when all you're doing is extracting the leaf node.

from yq.

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.