I have a json string where some part of it needs to be extracted and sent to a service. I am wondering if it’s possible to extract that specific part in jquery using expressions or any other approach?
the sample json I have is
{"hashcode":[], "stringMap":{":id":"50",":question":"My roof"}, ":size":"2", ":type":"java.util.HashMap", ":typeId":"123"}
and the string I want out of it is
{":id":"50",":question":"My roof"}
Thanks in advance.
Thanks for Inputs guys. I just realized that stringMap may have an arbitary name, like stringMap_0 etc.. can I still get that part out without exactly know that name?
thanks again.
Let’s be clear here that JSON is just Javascript Object Notation. So what you have is several objects:
Breaking this code down further, we find the following:
You can normally reference any one of these objects using “dot” notation in Javascript. The whole thing functions a lot like a Java Enum/Hashmap/ArrayList. However, because of those “:” you have throughout it is not going to work. Normally though, you could do the following (see POC here):
Note that in order for that code to work, I had to remove the “:” from before “id”…