Parse string as Json? - json
I have a json string but the format is strange
[[5706,[
[1132001,"Aston Villa","West Ham",5706,'2010-08-14T15:00:00.0000000',[[1966752,0],[1977724,1]],[],"","","","",64,63],
[1132002,"Blackburn","Everton",5706,'2010-08-14T15:00:00.0000000',[[1966753,0],[1977721,1]],[],"","","","",83,66],
[1132004,"Bolton","Fulham",5706,'2010-08-14T15:00:00.0000000',[[1966755,0],[1977727,1]],[],"","","","",88,85],
[1132005,"Chelsea","West Brom",5706,'2010-08-14T15:00:00.0000000',[[1966756,0],[1977712,1]],[],"","","","",503,94],
[1132006,"Liverpool","Arsenal",5706,'2010-08-14T15:00:00.0000000',[[1966757,0],[1977733,1]],[],"","","","",59,58],
[1132007,"Man Utd","Newcastle",5706,'2010-08-14T15:00:00.0000000',[[1966758,0],[1977730,1]],[],"","","","",19,70],
[1132008,"Sunderland","Birmingham",5706,'2010-08-14T15:00:00.0000000',[[1966759,0],[1977715,1]],[],"","","","",60,86],
[1132009,"Tottenham","Man City",5706,'2010-08-14T15:00:00.0000000',[[1966760,0],[1977739,1]],[],"","","","",62,77],
[1132010,"Wolves","Stoke City",5706,'2010-08-14T15:00:00.0000000',[[1966761,0],[1977718,1]],[],"","","","",81,342],
[1146485,"Wigan","Blackpool",5706,'2010-08-14T15:00:00.0000000',[[1998244,0],[1998321,1]],[],"","","","",350,328]],
[[1015824,8],[1035605,126]]]]
So, How can i parse and extract it value?
Thanks
Just eval it using whatever library is relevant to the language you're parsing it into. The format is a list of values and lists - so from the resulting structure you'll just need to traverse the lists to get to the pieces that you're interested in. Without more context, I can't provide any brilliant insight into what the values mean in those lists, but doing a little googlin' digging makes me thing you're looking at data related to football club tickets and/or games.
Related
JSON definition - data structure or data format?
What is more correct? Say that JSON is a data structure or a data format?
It's almost certainly ambiguous and depends on your interpration of the words. The way I see it: A datastructure, in conventional Comp Sci / Programming i.e. array, queue, binary tree usually has a specific purpose. Json can be pretty much be used for anything, hence why it's a data-format. But both definitions make sense
In my opinion both is correct. JSON is also a data format (.json) and also a data strucuture which you can use for instance in Java etc. But more correct is data strucutre.
JSON (canonically pronounced /ˈdʒeɪsən/ jay-sən;[1] sometimes JavaScript Object Notation) is an open-standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. It is the most common data format used for asynchronous browser/server communication (AJAJ), largely replacing XML which is used by AJAX. Source: Wikipedia
Which of the following are valid JSON documents?
Which of the following are valid JSON documents? {“name”:”Fred Flintstone”;”occupation”:”Miner”;”wife”:”Wilma”} {“title”:”Star Wars”, “quotes”:[“Use The Force”,”These are not the Droids you are looking for”],”director”:”George Lucas”} {} {“city”:”New York”, “population”, 7999034, boros:{“queens”, “manhattan”, “staten island”, “the bronx”, “brooklyn”}} {“a”:1, “b”:{“b”:1, “c”:”foo”, “d”:”bar”, “e”:[1,2,4]}}
This is obviously homework, so I will try to help you to come to the correct solution yourself, not just hand it to you. Look up which character is used to separate the individual key/value pairs from each other in a JSON document. One of the documents is using the wrong character. Look up the difference between objects and arrays in JSON. What's the difference and which characters are used to mark the beginning and end of either? The author of one of the documents tried to create an array, but uses the syntax for objects. The official JSON specification can serve as a reference for you.
Is there a Go Language equivalent to Perls' Dumper() method in Data::Dumper?
I've looked at the very similarly titled post (Is there a C equivalent to Perls' Dumper() method in Data::Dumper?), regarding a C equivalent to Data::Dumper::Dumper();. I have a similar question for the Go language. I'm a Perl Zealot by trade, and am a progamming hobbyist, and make use of Data::Dumper and similar offspring literally hundreds of times a day. I've taken up learning Go, because it looks like a fun and interesting language, something that will get me out of the Perl rut I'm in, while opening my eyes to new ways of doing stuffz... One of the things I really want is something like: fmt.Println(dump.Dumper(decoded_json)) to see the resulting data structure, like Data::Dumper would turn the JSON into an Array of Hashes. Seeing this in Go, will help me to understand how to construct and work with the data. Something like this would be considered a major lightbulb moment in my learning of Go. Contrary to the statements made in the C counterpart post, I believe we can write this, and since I'll be passing Dumper to Println, after compilation what ever JSON string or XML page I pass in and decode. I should be able to see the result of the decoding, in a Dumper like state... So, does any more know of anything like this that exists? or maybe some pointers to getting something like this done?
Hi and welcome to go I'm former perl hacker myself. As to your question the encoding/json package is probably the closest you will find to a go data pretty printer. I'm not sure you really need it though. One of the reasons Data::Dumper was awesome in perl is because many times you really didn't know the structure of the data you were consuming without visually inspecting it. With go though everything is a specific type and every specific type has a specific structure. If you want to know what the data will look like then you probably just need to look at it's definition. Some other tools you should look at include: fmt.Println("%#v", data) will print the data in go-syntax form. fmt.Println("%T", data) will print the data's type in go-syntax form. More fmt format string options are documented here: http://golang.org/pkg/fmt/
I found a couple packages to help visualize data in Go. My personal favourite - https://github.com/davecgh/go-spew There's also - https://github.com/tonnerre/golang-pretty
I'm not familiar with Perl and Dumper, but from what I understand of your post and the related C post (and the very name of the function!), it outputs the content of the data structure. You can do this using the %v verb of the fmt package. I assume your JSON data is decoded into a struct or a map. Using fmt.Printf("%v", json_obj) will output the values, while %+v will add field names (for a struct - no difference if its a map, %v will output both keys and values), and %#v will output type information too.
Convert a list to a JSON Object in erlang (mochijson)
i would really appreciate any help. I would like to convert this list [[{id1,1},{id2,2},{id3,3},{id4,4}],[{id1,5},{id2,6},{id3,7},{id4,8}],[...]] to a JSON object. Need some inspiration :) please help. Thank you.
Since you asked for inspiration, I can immagine two directions you can take You can write code to hand-role your own JSON which, if your need is modest enough, can be a very light-weight and appropriate solution. It would be pretty simple Erlang to take that one data-structure and convert it to the JSON. "[[{\"id1\":1},{\"id2\":2},{\"id3\":3},{\"id4\":4}],[{\"id1\":5},{\"id2\":6} {\"id3\":7},{\"id4\":8}]]" You can produce a data-structure that mochiweb's mochijson:encode/1 and decode/1 can handle. I took your list and hand coded it to JSON, getting: X = "[[{\"id1\":1},{\"id2\":2},{\"id3\":3},{\"id4\":4}],[{\"id1\":5},{\"id2\":6},{\"id3\":7},{\"id4\":8}]]". then I used mochison:decode(X) to see what structure mochiweb uses to represent JSON (too lazy to look at the documentation). Y = mochijson:decode(X). {array,[{array,[{struct,[{"id1",1}]}, {struct,[{"id2",2}]}, {struct,[{"id3",3}]}, {struct,[{"id4",4}]}]}, {array,[{struct,[{"id1",5}]}, {struct,[{"id2",6}]}, {struct,[{"id3",7}]}, {struct,[{"id4",8}]}]}]} So, if you can create this slightly more elaborate data structure then the one you are using, then you can get the JSON by using mochijson:encode/1. Here is an example imbeddied in an io:format statement so that it prints it as a string -- often you would use the io_lib:format/X depending on your application. io:format("~s~n",[mochijson:encode(Y)]). [[{"id1":1},{"id2":2},{"id3":3},{"id4":4}],[{"id1":5},{"id2":6},{"id3":7},{"id4":8}]]
Which word do you use to describe a JSON-like object?
I have a naming issue. If I read an object x from some JSON I can call my variable xJson (or some variation). However sometimes it is possible that the data could have come from a number of different sources amongst which JSON is not special (e.g. XMLRPC, programmatically constructed from Maps,Lists & primitives ... etc). In this situation what is a good name for the variable? The best I have come up with so far is something like 'DynamicData', which is ok in some situations, but is a bit long and not probably not very clear to people unfamiliar with the convention.
SerializedData?
A hierarchical collection of hashes and lists of data is often referred to as a document no matter what serialization format is used. Another useful description might be payload or body in the sense of a message body for transmission or a value string written to a key/value store. I tend to call the object hierarchy a "doc" myself, and the serialized format a "document." Thus a RequestDocument is parsed into a RequestDoc, and upon further identification it might become an OrderDoc, or a CustomerUpdateDoc, etc. An InvoiceDoc might become known generically as a ResponseDoc eventually serialized to a ResponseDocument. The longer form is awkward, but such serialized strings are typically short-lived and localized in the code anyway.
If your data is the model, name it after the model it's representing. e.g., name it after the purpose of the contents, not the format of the contents. So if it's a list of customer information, name it "customers", or "customerModel", or something like that. If you don't know what the contents are, the name isn't important, unless you want to differentiate the format. "responseData", "jsonResponse", etc... And "DynamicData" isn't a long name, unless there is absolutely nothing descriptive to be said about the data. "data" might be just fine.