Comments (5)
@msudgh In case it helps you or others who stumble across this, I created a wrapper module to recursively parse an object:
CommonJS Module: (recursive-dot-object.js)
const dot = require ( 'dot-object' );
const parseIt = obj => {
const parsed = dot.object ( obj );
for ( const [ key, value ] of Object.entries ( parsed ) ) {
if ( typeof value === 'object' ) {
parsed[ key ] = parseIt ( value );
}
}
return parsed;
};
module.exports = obj => {
return parseIt ( obj );
};
Test code:
const dotParser = require ( './recursive-dot-object' );
const data = {
request : {
query : {
'scopes.platformOwner': true,
'scopes.developers' : true
},
params: {
foo: 'bar'
}
},
'one.two.three': 123
};
console.log (
JSON.stringify( dotParser ( data ), null, 4)
);
Produces:
{
"request": {
"query": {
"scopes": {
"platformOwner": true,
"developers": true
}
},
"params": {
"foo": "bar"
}
},
"one": {
"two": {
"three": 123
}
}
}
from dot-object.
I did look through sources and see there is a constructor argument override
and noted that fixes the issues if I do the following:
> dot = new require('dot-object')('.', /*override:*/true);
DotObject { seperator: '.', override: true, useArray: true, cleanup: [] }
> x = { a: 1 }
{ a: 1 }
> dot.str('b', 2, x)
{ a: 1, b: 2 }
Can you explain the purpose of the override
parameter and if it has any other consequence?
This can be a work around for me, however imho it feels like the default behavior is an issue.
from dot-object.
The check for override was wrong in the str() method, I've updated it and pushed a patch release.
I notice the set() method is not described in the documentation, but you might as well use that one.
Currently they are almost the same, the difference being that str() allows a set of modifiers.
str = function (path, val, obj, mod)
set = function (path, val, obj, merge)
I'll look into joining them so both will have the same signature.
set = function (path, val, obj, mod, merge)
from dot-object.
Awesome - thanks for the info & the quick fix!
from dot-object.
I have a similar issue but a bit different.
Consider the following example as the request's body:
{
id: "1",
data: { "x.y": true }
}
but dot.object(req.body)
method is unable to parse it as the below expected:
{
id: "1",
data: {
x: {
y: true
}
}
}
Since it works with dot.object(req.body["data")
case i assume its not going to iterate deeply.
from dot-object.
Related Issues (20)
- Modifiers are not supported in transform operation
- transform operation: include unmapped fields in target objet
- Matching all elements of the given Array. HOT 1
- dot.object fails converting numeric nested json object HOT 1
- Math Operator on DotObject
- Using dot.pick with proxy object
- Missing license property in package.json
- Strange issue with dot-object bash script
- keepArray doesn't transform the elements of an Array
- Index number in object arrays HOT 2
- Numeric-key objects result in sparse arrays HOT 2
- dot.dot Nothing happens HOT 1
- Consider adding ESM output
- Generic `keep` option
- [Feature Request] Implement a `keepLastArray` option
- Querying keys with spaces and special separators in them
- Set/change value of property? HOT 1
- Bug with numeric object keys in arrays
- Memory leak in inflight dependency
- How to set `undefined` by `dot.set`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dot-object.