2

I have a situation where I am attempting to take some flat json input and provide some contextual information that is needed for API ingest. In the below example, I am trying to add some hardcoded keys into an array.

I've searched quite a bit but haven't seen this specific question asked.

JSON input

{
  "hostname": "computername",
  "user": "DOMAIN\\User",
  "full_name": "lastname firstname",
  "login_name": "DOMAIN\\User",
  "user_email": "[email protected]"
}

Expected outcome:

{
  "entities": [
    {
      "role": "hostname",
      "entities": [
        "computername"
      ]
    },
    {
      "role": "user",
      "entities": [
        "DOMAIN\\User"
      ]
    },
    {
      "role": "full_name",
      "entities": [
        "lastname firstname"
      ]
    },
    {
      "role": "login_name",
      "entities": [
        "DOMAIN\\User"
      ]
    }
  ],
  "user_email": "[email protected]"
}

Any help would be greatly appreciated!

1 Answer 1

1

You can use "$" wilcard to derive key names, and "@" wilcard to derive values of the respective attributes nested within a common object representation of a shift transformation such as

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "&.role",
        "@": "&.entities[]"
      },
      "user_*": "&"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "entities",
      "user_*": "&"
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/ is

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

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.