1

Received JSON:

 {
 "id": 313,
 "status": "blocked",
 "audit_pixels": [
 {
 "audit_pixel": "134307&ord={{random}}",
 "id": 1470355,
 "parent_id": null,
 "role": null
 },
 {
 "audit_pixel": "1087125871&ord={{random}}",
 "id": 1470356,
 "parent_id": 1470355,
 "role": "originalShow"
 },
 {
 "audit_pixel": "cid1115596-posid2396249",
 "id": 1470359,
 "parent_id": 1470357,
 "role": "originalShow"
 },
 {
 "audit_pixel": "cid1115596-posid2396249/{{random}}",
 "id": 1470360,
 "parent_id": 1470357,
 "role": "playbackStarted"
 },
 {
 "audit_pixel": "cid1115596-posid2396249/{{random}}",
 "id": 1470361,
 "parent_id": 1470357,
 "role": "playheadReachedValue100"
 }
 ]
 }

I want to remove elements from array audit_pixels:

  • where field role is null,
  • where field role role is not originalShow

EXPECTED RESULT:

 {
 "id": 313,
 "status": "blocked",
 "audit_pixels": [
 {
 "audit_pixel": "1087125871&ord={{random}}",
 "role": "originalShow"
 },
 {
 "audit_pixel": "cid1115596-posid2396249",
 "role": "originalShow"
 }
 ]
 }

Is it possible? I tried with:

[
 {
 "operation": "shift",
 "spec": {
 "*": {
 "id": "[&1].id",
 "status": "[&1].status",
 "audit_pixels": {
 "*": {
 "role": {
 "null": {
 "@(3,id)": "null"
 },
 "originalShow": {
 "@(3,id)": "audit_pixels.[&1]"
 }
 }
 }
 }
 }
 }
 }
]
asked Feb 20, 2024 at 15:43

1 Answer 1

1

You can use the following transformation :

[
 {
 "operation": "shift",
 "spec": {
 "*": "&",
 "audit_pixels": {
 "*": {
 "*": "&2.@1,role.@1,id.&"
 }
 }
 }
 },
 {
 "operation": "shift",
 "spec": {
 "*": "&",
 "audit_pixels": {
 "originalShow": {
 "*": {
 "audit_pixel|role": "&3[#2].&"
 }
 }
 }
 }
 }
]

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

enter image description here

answered Feb 20, 2024 at 16:31
Sign up to request clarification or add additional context in comments.

6 Comments

i'm sorry, maybe i was wrong at my description. I need role originalShow, but not others
Doesn't matter, just fixed it @fujidaon
Can u please also adapt this to if there only one element (json has only 1 object, not array like it was before)? Updated input and expected
Also I need only audit_pixel and role fields
Because I hadn't realized that you've tweaked the input then. Now, you can retry @fujidaon
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.