Comments (3)
I ended up copying and modifying shiftr to maintain an input stack instead of only the current input through the recursive apply() calls, and changed the AtPath reference to leverage BasePathAndGroupReference so I could optionally specify a path index value which is used walk up the stack. With these changes I can now use "@2": "&1.[]"
to accomplish what I needed. This enables a basic filter/sort capability where you can use drill down matching as criteria to determine which elements to shift.
[
{
"operation": "shift2",
"spec": {
"entities": {
"*": {
"type": {
"*": {
"@2": "&1.[]"
}
}
}
}
}
}
]
from jolt.
Interesting idea. Can please show me what the input and output look like for your new spec?
I think I get it now. The "@2" pulls the entire "{ type:alpha, data:foo }" block, then deposits in to "alpha.[]".
Neat.
from jolt.
One example is demonstrated in my original question, and is this:
Input
{
"entities":[
{
"type":"alpha",
"data":"foo"
},
{
"type":"beta",
"data":"bar"
},
{
"type":"alpha",
"data":"baz"
}
]
}
Spec
[
{
"operation": "shift2",
"spec": {
"entities": {
"*": {
"type": {
"*": {
"@2": "&1.[]"
}
}
}
}
}
}
]
Output
{
"alpha":[
{
"type":"alpha",
"data":"foo"
},
{
"type":"alpha",
"data":"baz"
}
],
"beta":[
{
"type":"beta",
"data":"bar"
}
]
}
Another (untested) example might be to filter out all but paperback books:
Input
{
"books": [
{
"title": "foo",
"availability": [
"online"
]
},
{
"title": "bar",
"availability": [
"online",
"paperback"
]
},
{
"title": "baz",
"availability": [
"paperback"
]
}
]
}
Spec
[
{
"operation": "shift2",
"spec": {
"books": {
"*": {
"availability": {
"*": {
"paperback": {
"@3": "PaperBooks[]"
}
}
}
}
}
}
}
]
Output
{
"PaperBooks":[
{
"title":"bar",
"availability":[
"online",
"paperback"
]
},
{
"title":"baz",
"availability":[
"paperback"
]
}
]
}
One behavior that could be better with this example though is if I used { "paperback|online": { "@4": "PaperBooks[] }
we end up with four books because the object with both paperback and online is duplicated. This is just an undesirable side effect of how matching is performed in the existing shiftr implementation, but that could probably be addressed.
from jolt.
Related Issues (20)
- remove null from simple type array
- ifElse multiple conditions? HOT 2
- Demo site source code
- Input JSON lost when doing a date concat
- bug on reading timestamp value HOT 1
- Sort wont work on an Array of complex Objects HOT 1
- squashNulls and recursivelySquashNulls need to work on arrays HOT 1
- concat elements of array HOT 3
- min\max for arrays
- Why is the key obtained from "&2" not "rating" HOT 6
- Help with Jolt transformation spec HOT 2
- How to compare fields between 2 JSON objects and create a response JSON in Jolt
- getrandom - target is not supported
- How to add an object to the end of an array with unknown length HOT 5
- Jo;t spec to remove fields having null and empty in the json having arraylist HOT 1
- need to replace a string using modify-overwrite-beta, REPLACE ABC string from attributes HOT 3
- how to read required attributes from a config file HOT 3
- What is jolt conversion spec for the given input and output
- The constructor of com.bazaarvoice.jolt.common.pathelement.StarDoublePathElement class could throw an unexpected ArrayIndexOutOfBoundsException
- Jolt Transformer for Splitting a field value HOT 2
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 jolt.