Comments (6)
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.
@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.
You are so fast! Thanks for such a great job. ๐ฅ
from dasel.
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.
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.
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)
- YAML: multiple documents in a single YAML file are not handled correctly HOT 2
- Dasel can't read arrays from yaml file without hyphen HOT 1
- The fields with null value just disappear in the output HOT 1
- Hex, binary and octal values are not parsed in yaml HOT 3
- Int instead of string added to a document HOT 4
- Manual Installation for Windows - Improvement HOT 4
- Converting JSON -> YAML -> JSON errors if timestamp fields are involved HOT 3
- Unable to select on CSVs without transforming to a different format HOT 3
- [REG 2.2->2.3] Superfluous quotes in selector output HOT 2
- Handle quotes in values HOT 2
- `dasel put --type string` not working when converting to yaml HOT 5
- Delete selector can't find keys with null values HOT 2
- Special characters inside string literals are replaced with Unicode escape sequences in JSON HOT 3
- contains/includes HOT 2
- -w xml is not working when -r is not xml HOT 3
- Support multiple files HOT 1
- CSV file format: Support other characters as separator HOT 2
- Output formatting is not right in some arrays HOT 6
- [BUG] Dasel crash when reading an empty file HOT 5
- Suppress header generation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dasel.