Delete key in JObject

Hi,

I need to delete a key from Jobject, but facing some confusion in methods.

Can anyone guide on this ?

{
data:{}
errors:{}
}

I want to delete error key

Invoke Code: yourJObjectVar.Remove(“errors”)

How to pass JObject var in invoke code ?

Create an argument as JObject and in/out

I did same

Don’t name your variable JObject. That’s a class. Create a proper variable name like myJObj or something.

image
Same error

Attached is sample Json , need to remove errors key
json.txt (4.6 KB)

JsonObject, again, is not a good variable name. You have to create variable names that don’t conflict with classes, properties, methods, etc.

Worked just fine for me…

image
image

image
image

image

Result output:
image

Not Sure, i tried same also getting same error, can we do using assign activity ?

Deserialize JSON - output: myJObject

grafik
myJObject.Property("errors")

as per Newtonsoft API the Remove methods are void / sub methods and do not have a return. Therefore we would use the invoke method activity

This one is working, not sure why invoke code is not working.

Hey, can we give array of property here.

Ok so topic can be closed
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

BTW:
grafik
with:

is also working

We do fully agree to @postwick

  • Do not use Keywords, Classnames …for variable names

Also do not use the same variable names for argument names / parameter names

Refer to the docu as it answers what is available and what not:

we would less recommend: Technically possible

arrRemoveProps = new String(){“errors”,“links”}

myNewJObject =
new JObject(myJObject.Properties.Where(Function (x) Not arrRemoveProps.Contains(x.Name)))

Show your code. You’ve got something improperly configured. Are you using the CTRL+K method to create your variables?

image