0

I have two JSON objects as input and want to add a value of one object to the other. I have tried many different specs, but I can't get it to work.

Here is an example of the situation:

Input:

{
  "all": {
    "a": "1",
    "b": "2",
    "c": "3"
  },
  "partially": {
    "d": "4",
    "e": "5",
    "f": "6"
  }
}

I want to have all data from the "all" object and I do not know what keys will be present. On the other hand I know the keys of the "partially" object and I want to shift only selected. So for example here is a desired output:

{
  "result" : {
    "a" : "1",
    "b" : "2",
    "c" : "3",
    "d" : "4"
  }
} 

This is my current spec, but it produces an array with separate data and does not select only "d" from the "partially". If I try to select only "d" it shifts the value but not the key, but I need both:

[
  {
    "operation": "shift",
    "spec": {
      "all": "result",
      "partially": "result"
    }
  }
]

Is there any way to do this? Thank you!

1 Answer 1

2

Please try this spec,

[
  {
    "operation": "shift",
    "spec": {
      "all": {
        "@": "result",
        "@(1,partially.d)": "result.d"
      }
    }
  }
]
Sign up to request clarification or add additional context in comments.

1 Comment

This is not very important, but is it possible to sort the output of "result" the other way around? So that "d" would be the first entry in "result" as so: "d", "a", "b", "c"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.