json valueEncoding doesn't work as expected
See original GitHub issueI use json valueEncoding for v1 and it works without any problem.
After upgrade to v2, It does not work anymore: after putting an object to leveldb, we will get back a [object Object]
value of string
type.
The following code can be able to reproduce the problem:
import * as encoding from 'encoding-down'
import * as leveldown from 'leveldown'
import * as levelup from 'levelup'
async function main() {
const encoded = encoding(leveldown('/tmp/test'), {
valueEncoding: 'json',
})
const levelDb = levelup(encoded)
await levelDb.put('test', {a: 1})
const value = await levelDb.get('test')
console.log('value type:', typeof value) // value type: string
console.log('value:', value) // value: [object Object]
}
main()
"dependencies": {
"encoding-down": "^2.2.1",
"leveldown": "^1.8.0",
"levelup": "^2.0.0-rc3",
}
After a little digging, I found the following code in AbstractLevelDOWN, which is just String(value)
for the value.
AbstractLevelDOWN.prototype._serializeValue = function (value) {
if (value == null) return ''
return this._isBuffer(value) || process.browser ? value : String(value)
}
I have no idea how to fix it because there’s too many modules/layers.
Issue Analytics
- State:
- Created 6 years ago
- Comments:22 (22 by maintainers)
Top Results From Across the Web
JSON Encode/decode doesn't work as it should - Stack Overflow
Sending a JSON object to PHP and trying to decode it there fails. I believe I would need to remove the parentheses in...
Read more >web services server operation-how to accept encoded urI in ...
I need to receive the requested encoded data and decode it so that i can read the mac address value in the request....
Read more >Custom encoding and decoding JSON in Swift
How to decode a JSON data object into a readable Swift struct; Usage of custom keys; Custom objects creation; Arrays; Different top level ......
Read more >Writing custom JSON encoding and decoding logic
My CodingKeys all use their generated raw value which means that I expect my JSON to perfectly mirror the properties in this struct....
Read more >JSON and Go - The Go Programming Language
To encode JSON data we use the Marshal function. ... Unmarshaling that data into a FamilyMember value works as expected, but if we...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Will fix this today or tomorrow. After that I think we should release 2.0.0.
right. damn lockfiles 😃