[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Is JSON the best way to structure data before sending it over
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 82
Thread images: 8
File: unnamed.png (66 KB, 640x400) Image search: [Google]
unnamed.png
66 KB, 640x400
Is JSON the best way to structure data before sending it over a network?

It certainly looks less faggy than XML at least.
>>
>>54657871
yes, it's pretty much the standard
>>
>>54657871
jason is a meme for node.js fags
>>
>>54657918
>parsing xml in any language
huge meme
>>
>>54657918
but it just werks
>>
>>54657871

If you're sending text then definitely use json.
>>
Just use CSV or something like that
>>
>>54657871
yes
>>
>>54657985
CSV is flat, you can't represent the structure in OP's image in csv.
>>
>>54657871
no use Apache Thrift, Apache Avro or Google Protocol Buffers
>>
>>54657918
angle bracket tax
>>
>>54658007
>CSV is flat,
CSV is actually arbitrarily-dimensioned, you can use as many distinct separators as you want.

Using numpy with some external simulation packages, tensors matrixes and larger data structures are all passed via CSV
>>
>>54658007
Oh you can, it's just a giant pain. Need to use either generic columns and references or a large number of columns and references.

I'm an SI, I have some customers that do this. It's batshit insane
>>
>>54657871
i mean it's bretty gud
use compression if possible
>>
>>54657871
pretty much
there's a reason almost every major website with any form of api uses it
>>
File: 1409598869923.jpg (9 KB, 300x137) Image search: [Google]
1409598869923.jpg
9 KB, 300x137
>>54657934
>tfw writing a one-off console app that molests some SVG files by directly modifying the xml to fix cropping issues
>>
File: jasononsuicidewatch.png (46 KB, 892x411) Image search: [Google]
jasononsuicidewatch.png
46 KB, 892x411
>>54657985
This desu

JSON wastes a fuckton of bytes
>>
json is for brogrammer faggots who can only write "apps" in html and ruby.

.txt for the master race programmers who know their shit.
>>
>>54658007
Yes, you can. You're obviously a not very brilliant person. I wish the hierarchical data meme would just die, people have had more than enough time to learn object-relational data by now.
>>
>>54657871
It's stupid data structure IMO because the parsing isn't straightforward. Readability isn't that much better than XML. Like what another anon suggested, CSV is better. Whoever designed JSON and thought it's a good data structure for internet use is an idiot because it has no advantages over simpler, more efficient formats.
>>
>>54658031
Yeah but not everything is numeric computer and not everything deals with matrices of numbers.
If you want a matrix then obviously use something like CSV that easily represents a matrix. But if you want remotely "rich" data then JSON is literally perfectly fine, is readable and concise, easy to parse, has lots of implementations in lots of languages. Hating it because "simplicity is better and CSV is more simple!" is retarded.
>>
>>54658559
>I don't know what I'm talking about, the post
Hi pajeet
>>
File: b9c.png (186 KB, 540x343) Image search: [Google]
b9c.png
186 KB, 540x343
>>54657871
Define "best".
If you're looking for the most efficient way on the wire, then binary would be the best.
>>
>>54659887
Binary is shit. Hexadecimal is better.
>>
>>54659906
Base64 is Best64
>>
>>54659601
Considering that most json is machine generated and effectively has no whitespace I actually found it small enough for Web configuration stuff vis a vis CSV with the upside of getting to be lazy about parsing it in PHP ot jQuery.
>>
>>54659887
Binary isn't a data structure.
>>
>>54659601
>But if you want remotely "rich" data then JSON is literally perfectly fine, is readable and concise, easy to parse, has lots of implementations in lots of languages.

It's neither easily readable, concise, nor easy to parse. The fact that it's popular doesn't mean necessarily it's good. Tables are always easier to read and more efficient.
>>
>>54659973
Json is trivial to parse, with a well defined, minimal set of control characters and a well defined minimal set of data containers.

It's only barely harder than string.split
>>
>>54657871
>not using HSON
wew lad

https://hjson.org/
>>
>>54657871
Are there even any decent alternatives to JSON?
>>
>>54660427
Can a parser trivially distinguish between a string and a number?
How does it encode newline? Tab?
Why are there comments in a computer generated serialization format?
>>
>>54660455
Somebody is going to argue yaml, another person about sexprs. They would have any point at all if the parsers weren't slower and more complex than XML
>>
>>54660424
>Json is trivial to parse
>It's only barely harder than string.split
not nearly as trivial as CSV, which is _literally_ string.split or substring
>minimal set of control characters
not as minimal as CSV's: "," and ";"
+ have to escape any string with the " symbol in it
>well defined minimal set of data containers
data containers?
you mean fields?
>>
>>54657871
>JSON
Easy to use universal structured data format.

>XML
For MARKUP, like if you need to send custom text document types.

>INI/YAML
For app configuration.

>roll your own binary format
If you absolutely need the performance.
>>
>>54657871
JSON all the way babyyyy
>>
txt is for faggy wannabe hackers in their mom's basement, use HDF5 instead, it's used by scientists.
>>
>>54660521
>You mean fields
No, I mean string, number, array, unordered map
>>
>>54660521
>Literally string.split
>Except for newline
>except for strings containing the delimiter
>except for partial lines and empty elements
>except for anything having to do with utf8
You might as well decode base64 for all the "easy" CSV transmission will give you
>>
>>54660629
>Not using hl7, the superior health care format
>>
>>54657871
What does best mean? It's certainly quite nice if the data is required to be human readable, but if you're looking for pure serialization/deserialization performance, then one of the libraries that uses some binary wire protocol that doesn't have to be human readable is probably going to be faster and produce a smaller output message (like Protocol Buffers). If you really want to get down to it you could probably write your own application-specific protocol from scratch and have absolutely minimal overhead.
>>
JSON are good enough for web rpc.

CSV although look simple could have more overhead due to writing your own parser and escaping possible delimiter.

JSON parser are done by browser itself.

As for binary vs text, don't bother.
Instead, go for HTTP/2 and save yourself from complexity of data compression.
>>
>>54657871
>he doesn't use the jsonapi specification
http://jsonapi.org/
>>
>>54657902
>standard
>>
>>54658205
now select some value by key.
>>
>>54658559
it's piss easy to parse, I wrote my own library for that in like 50 lines of code (and could probably make it even shorter)
anyways, if y'all want something compact and easy to parse, s expressions are clearly the best
>>
>>54661013
>strawman

Still doesn't change the fact that CSV is easier to parse than JSON.
>>
>>54663034
do you know what a strawman is? the first guy said it's _literally_ string.split(). idk what you think "_literally_" means but he addressed the argument exactly as it was presented
>>
File: 1458324829913.jpg (39 KB, 540x540) Image search: [Google]
1458324829913.jpg
39 KB, 540x540
{
"the most": ["annoying", "thing", "about", "json"],
"is_how": "anyone",
"in_their_right_mind": null,
"could_think_that_this": {
"is": [{
"a":
"readable": false
},
{"desirable": "data serialization format"}
{"to_the_point": [{
"where": "they would type it out manually and consider it convenient and clever and amazing"
},{
"kind_of": "like how proud of their genetically assigned role in society gammas, deltas, and epsilons were to be in brave new world"
}]}]}
>>
>>54663034
>parsing csv tree structures is easier to parse than simple dict lookups
print('\n'.join(post['com'] for post in data['posts']))

Tell me how you are going to print all comments in a thread as elegantly as that using csv. Even that task is simple
>>
>>54663151
nobody types json out manually you dumb shit. It's generated from objects
>>
>>54662334
faggot = you[0]
>>
>>54663071
>he addressed the argument exactly as it was presented

No he didn't. He ignored "or substring".

>>54663155

White space isn't part of the JSON standard.
>>
>>54657918
Just from my uses it is quick and easy to parse with Ruby and it is the format for setting policy in AWS. It has a much broader use than node even though you are likely just trolling.
>>
If you are not using json you are a meme
>>
>>54657871

In my experience, it's actually pretty rare to actually need tree structured data. Most data people want can be represented easily as key=value pairs or csv.

If you need tree structure, JSON is only better because every scripting language supports it. If you need to do any parsing yourself, use s-expressions.
>>
Everyone now a days uses Json OP, people are saying otherwise are either trolling or Neets who dont even work.
>>
>>54663151
>readability
you have to be a woman
>>
>>54664039
>White space isn't part of the JSON standard.
That has nothing to do with my post. I'm not making json, I'm accessing it
>>
>>54657871
JSON is fine for most things. Has the advantage of being decently human-readable and standard.

If you are sending a lot of data you might want o look into transit.
>>
>>54664985
>into transit.
I meant MsgPack
>>
Is JSON a good idea for a protocol that works over UDP?
>>
>>54658013
Protocol buffers is definitely the way to go
>>
File: pb_json.png (24 KB, 784x370) Image search: [Google]
pb_json.png
24 KB, 784x370
>>54665358
This
>>
>>54665599
Doesn't that use a library provided by Google?
>>
File: js.png (24 KB, 500x500) Image search: [Google]
js.png
24 KB, 500x500
>>54657871
Could someone explain me what the is the difference between plain text in body and JSON if you to change js object to a normal string with json stringify before sending it back?
>>
>>54666003
Do they actually call the function "stringify"? Damn, what a bunch of hilarious, silly, all-casual chucklemasters the json developers must be.
>>
>>54657871
xml takes more space too i would guess because of the closing tags
>>
>>54665599
JSON is a presentation layer protocol. It doesn't have anything to do with getting your data transferred over from A to B. Your image makes no sense.
>>
>>54657871
>lines separated by commas

This triggers my autism. What kind of language forces you to use commas so often? I only feel like I've made a complete statement after using a semicolon.
>>
>protocol buffers
Just use json schema you neet
>>
>>54659601
Hell we literally use JSON strings as XML attribute values in our XML-based config files (.NET stuff) because it's often easier to read and deal with complex configuration that way than to implement an equivalent XML structure
>>
>>54666141
Whats the best way to communicate server-client, if you are coding in C?
>>
>>54666274
I don't know man, why don't you googlify it?
>>
the beauty of json is that you can have fairly complex nested data structures of arrays and hashes, convert it to json, send it over the wire, and then with one line of code turn it back into your data structure.
>>
>>54658205
nice bait
>>
>>54660475
>>Why are there comments in a computer generated serialization format?
Because it can now be used as a configuration format.
>>
>>54657871
>Is JSON the best way to structure data before sending it over a network?
yes
>>
>>54666327
Well it does waste a lot
>>
>>54657871
>It certainly looks less faggy than XML at least.
>>54657934

Until you need to store rich text content. Then, out of all sudden, you'll start sucking XML/HTML5s dick soon enough.

>>54666327
He has a point, though. It's not exactly a compact format.
>>
>>54657871
>not writing your own parser that is more efficient than xml, json or csv.

Plebs. My datastream had an overhead of 3 bytes per nested object and parsed 2 to 5 megabytes per second depending on tree depth.
>>
>>54657871
GraphQL
Thread replies: 82
Thread images: 8

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.