Giter Site home page Giter Site logo

Transformation problem about jolt HOT 5 CLOSED

bazaarvoice avatar bazaarvoice commented on September 16, 2024
Transformation problem

from jolt.

Comments (5)

milosimpson avatar milosimpson commented on September 16, 2024

Questions:

  1. How can I aggregate "a" and "b" to one value (if all values are the same)?

Jolt / Shift does not do aggregates, it just transforms the structure of your data.
That said, it can transform your data into a structure that is easier for you to aggregate.
With "a" : [ "t1", "t1", "t1" ] , it is easier to see if all the values are the same.

  1. How can I add to elements of array "c" some children from top level of json?

Looking at your example, I think I see what you want to accomplish.

    if ( c == t3 ) then grab "d" and "e" and nest them under c.t3[]
    else if ( c == t4 ) then grab "d" and "e" and nest them under c.t4[]

That is custom logic, and you would need to write a Java Transform.

  1. Maybe another questions will appear later
    or maybe this problem cannot be resolved using lastest (0.0.12) version of JOLT?

Yeah, there are ideas on how to do this, but no definative plans.

from jolt.

sashevsky avatar sashevsky commented on September 16, 2024
  1. Understood, thank you
  2. Sorry, maybe I was poorly expressed.
    Can I add child nodes to this array's ( { "c" : [ "t3", "t3", "t4" ] } - it is from result)
    elements for get json like this:
{
"c": {
        "t3": [
            {
                "d": "t5",
                "e": "t8"
            },
            {
                "d": "t6",
                "e": "t9"
            }
        ],
        "t4": [
            {
                "d": "t7",
                "e": "t10"
            }
        ]
    }
}

Thanks

Update:
2. Yes, You are right. I know how to do it in Java :) Maybe in future release it would be available in JOLT :)

Thanks for answering my question 👍

from jolt.

milosimpson avatar milosimpson commented on September 16, 2024

When I look at where "d": "t5" came from, it looks like you are trying to "group by" c == t3.
Best "shift" could do is strip out "a" and "b" from each input.
Spec of

[
    {
        "operation": "shift",
        "spec": {
            "*": {
                "a": "A",
                "b": "B",
                "c|d|e": "C[&1].&"
            }
        }
    }
]

Produces :

{
  "A" : [ "t1", "t1", "t1" ],
  "B" : [ "t2", "t2", "t2" ],
  "C" : [ 
     {
      "c" : "t3",
      "d" : "t5",
      "e" : "t8"
    }, 
    {
      "c" : "t3",
      "d" : "t6",
      "e" : "t9"
    }, 
    {
      "c" : "t4",
      "d" : "t7",
      "e" : "t10"
    } 
 ]
}

from jolt.

sashevsky avatar sashevsky commented on September 16, 2024

Yes, the best name for that I need to do is "group by".
Thanks for Your example but this is not exactly what I need.
I understood that now I cannot use JOLT for my task, maybe later:)

from jolt.

milosimpson avatar milosimpson commented on September 16, 2024

If you are willing to do a series of Shifts, it can get you the unique values of "a" and "b"

Input : Note I changed the 2nd "a = t1" to "a = t2".

[
    {
        "a": "t1",
        "b": "t2",
        "c": "t3",
        "d": "t5",
        "e": "t8"
    },
    {
        "a": "t2",
        "b": "t2",
        "c": "t3",
        "d": "t6",
        "e": "t9"
    },
    {
        "a": "t1",
        "b": "t2",
        "c": "t4",
        "d": "t7",
        "e": "t10"
    }
]

Spec

[
    {
        "operation": "shift",
        "spec": {
            "*": {
                "a": "A",
                "b": "B"
            }
        }
    },
    {
        "operation": "shift",
        "spec": {
            "A": {
                "*": {
                    "*": "a.&"
                }
            },
            "B": {
                "*": {
                    "*": "b.&"
                }
            }
        }
    },
    {
        "operation": "shift",
        "spec": {
            "a|b": {
                "*": {
                    "$": "&2"
                }
            }
        }
    }
]

Output

{
  "a" : [ "t1", "t2" ],
  "b" : "t2"
}

from jolt.

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.