0

I have this JSON in a string:

{"variables": [{"name": "variable1", "type": "Integer", "id": 0, "asInput": [], "asOutput": [], "onSet": []}], "scripts": [], "action": "updateConfiguration"}

Here is a part of a JavaScript script:

console.log(myString)
var myObject = JSON.parse(myString)
console.log(myObject)

I see the JSON above for the console.log(myString), but this is what I see for the console.log(myObject) part:

{
    "variables": [
        {}
    ],
    "scripts": [],
    "action": "updateConfiguration"
}

The JSON is valid as per JSONlint.

Why is the object inside the variables array empty?

(BTW, the same issue arises with the elements of scripts if it has any.)

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Silverspur
  • 891
  • 1
  • 12
  • 33
  • 2
    [Works for me](https://jsfiddle.net/tjcrowder/8qdyavp3/), `variables` has variables in it. – T.J. Crowder Feb 23 '19 at 10:58
  • Just now i have checked in json editor your json data was not valid json format – jvk Feb 23 '19 at 10:58
  • 1
    @KrishnaJonnalagadda - The question is a bit unclear, the block with the JSON is the output of the code above. Only the *first* line of that block is the actual JSON (which is valid). – T.J. Crowder Feb 23 '19 at 10:58
  • 1
    See the linked question's answers. The explanation for this is probably that the JSON parses just fine, complete with entries in `variables`, `scripts`, etc., but then *after* the `console.log` but *before* you expand that entry in the console, code removes the contents of `variables` and `scripts` (or overwrites those properties entirely). If you replace `console.log(myObject);` with `console.log(JSON.stringify(myObject));`, the full contents at that point in time will be shown. – T.J. Crowder Feb 23 '19 at 11:00

0 Answers0