1

I have a string that carry the path of a nested json, where I need to update a value

var path = 'p_Data[0]["BusinessUnit"][0]["BusinessUnit"]' 

if i evaluate this path I get value as 'Unit1'. I need to update the value 'Unit1' with 'Closed' and retrieve the original data ie, p_Data

I tried eval(path = 'Closed'), but didn't work.

How to do this?

6
  • did you use jsonpath??? It's a good plugin to manipulate json strings.... Commented Aug 7, 2013 at 8:44
  • @maverickosama92: isn't there any other way to do this other than having another plugin? Commented Aug 7, 2013 at 8:46
  • FWIW, that's not a JSON string, that's just a string. And I assume you already parsed the JSON data and work with nested objects (so the problem does not have anything to do with JSON). Have a look at Javascript: How to set object property given its string name for a start. Commented Aug 7, 2013 at 8:53
  • @FelixKling 'JSON string' was a careless mistake sry Commented Aug 7, 2013 at 8:57
  • I haven't worked much with nested JSON this is my first try with nested. Commented Aug 7, 2013 at 8:58

1 Answer 1

1
eval(path + "='Closed'"); 

But have a look at this thread: Why is using the JavaScript eval function a bad idea?.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.