New answers tagged

2

It's certainly being done, but I think whether it's a good idea depends on the style and size of application. How big is this application and how long will it live? It's harder to trace behavior and refactor with a very long path of code that might rely on the object-properties and relationships, meaning it has to be inspected and fixed as a unit. (As ...


1

The most efficient would probably be a binary format which you could read directly into memory, skipping the parsing step.


2

You can do better than either XML or JSON by exploiting the particular characteristics of your particular data. If the data is completely flat and every row contains the same fields, then CSV is going to be more efficient than either XML or JSON. The reason people generally prefer formats like XML and JSON is because they recognise that the life-time cost of ...


0

Can you expand on what you mean by dynamically add properties? I take it that you need to do this while code is running, rather than simply edit the source files? If so maybe check out named tuples as part of the Python collections module https://docs.python.org/2/library/collections.html You can create a class dynamically like this EmployeeRecord = ...


6

On languages such as Haskell, most datatypes have instances which allow their values to be used as keys of structures such as Maps. It's the same in ECMAScript. Any object, including primitives, can be used as the key in a Map. Even NaN, even though NaN !== NaN // true does the right thing and can be reasonably used as the key in a Map. JavaScript ...


3

What you really want is a Map, not an object: Map You need to check if the support you need to provide fits with the Map supported browsers, but that´s what you really want as objects only take strings or symbols as keys while a map can take anything Here is an example of its usage: var point1 = {"x": 7, "y": 8, "z": 9}; var point2 = {"x": 6, "y": 5, ...


0

When writing GoJS we solved this by having the following rules for data: Every node has a key, which must be unique Links can be represented one of two ways: In a Tree-like fashion (TreeModel), or as separate JSON object entities (GraphLinksModel) If the flowchart or diagram is created in a Tree-like fashion, with only one parent per Node, then you don't ...


0

What I did was use self.__dict__.update(json) which copies items in the JSON dict into the object's dict and so they appear as properties of the object. The client can then use dot notation to access or mutate them.


0

Since you mention you have control over the json with Java (in other words at the backend). I always favor shielding a front-end of these sort of proprietary concerns. Let Java create a json file that will fit like a glove, normalize the data before sending it across the wire.


1

You can really have anything you want in the JSON response as long as you define it as a standard and adhere to it. Naturally, you then need to parse the standardized JSON response in your code according to the presented rules. However, I don't like the current design and would have redesigned the JSON response (from your recent comment it seems you have ...


1

Sorry to say there is no elegant way of this messy design. If you had some control it would be better to split these magic values into a plain array where each propertiy is of one type. regarding your suggestion of "mykeytype":"boolean" some json libraries support this out of the box. Example json.net you can set typenamehandling=auto and it will add an ...



Top 50 recent answers are included