'JSON error: " Expecting 'STRING', '}', got 'undefined'"

EDIT: I changed the single-quotes to double-quotes and the linters don't complain.

I put this into jsonlint.com and I got this error:

Error: Parse error on line 1:
{   'bandwidth_in': {       
--^
Expecting 'STRING', '}', got 'undefined'

Similar results for other json linters. Originally, the numeric values were bare, so I wrapped those in single quotes to get rid of the jq error:

parse error: Invalid numeric literal at line 2, column 16

But I still get that for jq.

I don't see any undefined keys, what am I missing?

{
    'bandwidth_in': {
        'GE4': {
            'value': '16292',
            'tree': {
                '2': {
                    'name': 'GE4',
                    'key': 'GE4',
                    'attributes': {
                        'snmp_index': 'GE4'
                    }
                }
            },
            'attributes': {
                'bandwidth': '15157250.0'
            }
        }
    },
    'bandwidth_out': {
        'GE4': {
            'value': '14616',
            'tree': {
                '2': {
                    'name': 'GE4',
                    'key': 'GE4',
                    'attributes': {
                        'snmp_index': 'GE4'
                    }
                }
            },
            'attributes': {
                'bandwidth': '15150500.0'
            }
        }
    },
    'jitter_in': {
        'GE4': {
            'value': '0.0',
            'tree': {
                '2': {
                    'name': 'GE4',
                    'key': 'GE4'
                }
            }
        }
    },
    'jitter_out': {
        'GE4': {
            'value': '0.002',
            'tree': {
                '2': {
                    'name': 'GE4',
                    'key': 'GE4'
                }
            }
        }
    },
    'latency_in': {
        'GE4': {
            'value': '0.001',
            'tree': {
                '2': {
                    'name': 'GE4',
                    'key': 'GE4'
                }
            }
        }
    },
    'latency_out': {
        'GE4': {
            'value': '0.003',
            'tree': {
                '2': {
                    'name': 'GE4',
                    'key': 'GE4'
                }
            }
        }
    },
    'packetloss_in': {
        'GE4': {
            'value': '0',
            'tree': {
                '2': {
                    'name': 'GE4',
                    'key': 'GE4'
                }
            }
        }
    },
    'packetloss_out': {
        'GE4': {
            'value': '0',
            'tree': {
                '2': {
                    'name': 'GE4',
                    'key': 'GE4'
                }
            }
        }
    }
}

I also saw a reference online that bare numbers for keys aren't allowed, would it be fair to say that any JSON with non-string keys should not pass muster?



Solution 1:[1]

As Remy Labeau stated

strings don't support single-quotes as delimiters, only double-quotes.

When you have a String containing inline JSON, you have some options:

outter double quotes and inner escaped double quotes

sJson = "{\"key\":\"value\"}"

outer single quotes

sJson = '{"key":"value"}'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 randmin