question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

json valueEncoding doesn't work as expected

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:22 (22 by maintainers)

github_iconTop GitHub Comments

2reactions
ralphtheninjacommented, Oct 2, 2017

Will fix this today or tomorrow. After that I think we should release 2.0.0.

1reaction
vweeverscommented, Oct 7, 2017

right. damn lockfiles 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found