0

A quick overview of the situation:

For simplicity of complicated data, I've got a series of JavaScript objects (built using function Object Factories) that handle auditing data, so for example, you have a child object inside a parent object inside a user object (these are basically arrays). These objects contain functions that help process the data they contain, both in and out, when in the UI.

On the top level, a single JSON function call pulls the data the objects contain out, without the functions (which is what I want to happen, as only the data is stored in an external database).

The problem

However, on pulling the information back from the database, using JSON.parse and assigning the result into the top level object holder obviously only contains just the data, no functions.

Bearing in mind the object arrays won't be initialised (as they won't know the length until extracted from the JSON data), how can I reinsert the JSON data back into the objects, functions included?

Is there some way of saying to the parser 'for this level of data, use this object, for this level, use this one'?

[Note: due to the nature of the organisation and security, external libraries aren't permitted. No jQuery suggestions etc.]

SE Does Not Like Dissent
  • 1,767
  • 3
  • 16
  • 36
  • Why do you have functions that you are trying to execute from within a parsed JSON file? That sounds like a security vulnerability in itself. – Obsidian Age Jul 03 '17 at 21:34
  • A Javascript Object and JSON (JavaScript Object Notation) are slightly different. JSON doesn't allow functions in it. If you're storing your data, why not use it to recreate the objects using the same way you made it the first time? – Khauri Jul 03 '17 at 21:47

0 Answers0