S
S
semki0962020-02-12 10:28:23
JavaScript
semki096, 2020-02-12 10:28:23

How to detect error in json?

For example, json (taken from the documentation https://github.com/d3/d3-dsv )

[{"foo": "1", "bar": "2"}, columns: ["foo", "bar"]]

I can not understand what is doing here. In addition, this code as json is not valid. What's wrong with him? I would be grateful for help. , columns: ["foo", "bar"]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2020-02-12
@semki096

This is not valid JSON - as JSON, no one will use this comment from the documentation. But the comment gives an idea of ​​the structure that the described method returns.

The returned array also exposes a columnsproperty containing the column names in input order (in contrast to Object.keys, whose iteration order is arbitrary).

The method returns an array that also has a "columns" property.
In JavaScript , an array is also an object . With its properties and methods. And why not create another property for the object.
var a = [11,22];
a.columns = [333, 444];

JSON.stringify(a)
> "[11,22]"

JSON.stringify(a.columns)
"[333,444]"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question