Giter VIP home page Giter VIP logo

Comments (6)

TomWright avatar TomWright commented on May 22, 2024 1

I have created a feature request for this problem: #67

For a more specific example in this use-case I would expect something like this:

echo 'foo: true
bar: 5
baz:
  qux: false
  quux: "yes"
  quuz: 7' | dasel put document -d json '.baz' $(echo '[
 {
 "qux": false,
 "quux": "no",
 "quuz": 8
 }
]' | dasel -p json '.[0]')

Sudo code explanation with placeholders

JSON_ARRAY =

[
 {
 "qux": false,
 "quux": "no",
 "quuz": 8
 }
]

YAML_CONTENT =

foo: true
bar: 5
baz:
  qux: false
  quux: "yes"
  quuz: 7

The JSON_ARRAY isn't actually what we want to use, so we extract the first item from the array.

JSON_DOCUMENT = echo JSON_ARRAY | dasel -p json '.[0]'

{
  "qux": false,
  "quux": "no",
  "quuz": 8
}

Finally we put the extracted json document into the yaml content using the baz property.

echo YAML_CONTENT | dasel put document -d json '.baz' JSON_DOCUMENT

from dasel.

TomWright avatar TomWright commented on May 22, 2024 1

@Dentrax This is now supported as of v1.10.0.

Command:

echo 'foo: true
bar: 5
baz:
  qux: false
  quux: "yes"
  quuz: 7' | dasel put document -p yaml -d json '.baz' "$(echo '[
 {
 "qux": false,
 "quux": "no",
 "quuz": 8
 }
]' | dasel -p json '.[0]')"

Output:

bar: 5
baz:
  quux: "no"
  quuz: 8
  qux: false
foo: true

from dasel.

Dentrax avatar Dentrax commented on May 22, 2024 1

You are so fast! Thanks for such a great job. ๐Ÿ”ฅ

from dasel.

TomWright avatar TomWright commented on May 22, 2024

Hey @Dentrax,

Thanks for your question.

The docs on replacing objects can be found here: https://github.com/TomWright/dasel#put-object

It doesn't look like dasel can do what you need yet though - you need to define the object property by property.

I think a new put document command could help out here.

from dasel.

TomWright avatar TomWright commented on May 22, 2024

Additionally the docs on converting between different data formats are here: https://github.com/TomWright/dasel#converting-between-formats

I will soon create a new feature request issue for a put document command that should solve your issue.

from dasel.

Dentrax avatar Dentrax commented on May 22, 2024

Thanks for documentations and prompt response! I guess I missed that parts. :) This will be great feature. I will look forward to it.

What I am concerning about is how to use put document in cross formats. i.e.:

YAML

foo: true
bar: 5
baz:
  qux: false
  quux: "yes"
  quuz: 7

JSON

[
 {
 "qux": false,
 "quux": "no",
 "quuz": 8
 }
]

As we all know, this JSON is in list of objects format. If we want to put document any JSON object (i.e. first array item) to YAML's baz, what command should we execute in this scenario?

from dasel.

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.