JSON sample not working
2 posts
• Page 1 of 1
JSON sample not working
I started looking at the JSON I-beams and my very first sample did not work. Here it is
- Code: Select all
A
{"first_name" : "Neeraj",
"last_name" : "Gupta",
"stocks" :
[
{"S1":"IBM"},
{"S2":"MSFT"}
]
}
j←0 (7159⌶) A
j.stocks.⎕nl 2
S1 S2
j.stocks.S1
VALUE ERROR
j.stocks.S1
∧
- neeraj
- Posts: 82
- Joined: Wed Dec 02, 2009 12:10 am
- Location: Ithaca, NY, USA
Re: JSON sample not working
Hi Neeraj,
Actually it is working properly.
j.stocks is a 2 item vector of JSON objects
If you turn ]box on, you can see that j.stocks.⎕NL -2 is a 2 item vector of namelists.
S1 is in the first item, and S2 is in the second.
j.stocks.S1 is referring to the S1 element in all items, and the VALUE ERROR occurs because there is no S1 element in the second item.
So, to reference S1 and S2 you need to select the appropriate item.
Actually it is working properly.
j.stocks is a 2 item vector of JSON objects
j.stocks
#.[JSON object].[JSON object] #.[JSON object].[JSON object]
If you turn ]box on, you can see that j.stocks.⎕NL -2 is a 2 item vector of namelists.
z.stocks.⎕NL -2
┌────┬────┐
│┌──┐│┌──┐│
││S1│││S2││
│└──┘│└──┘│
└────┴────┘
S1 is in the first item, and S2 is in the second.
j.stocks.S1 is referring to the S1 element in all items, and the VALUE ERROR occurs because there is no S1 element in the second item.
So, to reference S1 and S2 you need to select the appropriate item.
j.stocks[1].S1
IBM
-
Brian|Dyalog - Posts: 116
- Joined: Thu Nov 26, 2009 4:02 pm
- Location: West Henrietta, NY
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group