Comments (3)
do you have the latest version of flatten_json
? try upgrading and try again
pip install --upgrade flatten_json
i'm get this output with your example:
{'seo': {'test': 'hello'}}
from flatten.
I have the latest version of flatten_json installed. I'm running Python 2.7, pip 9.0.1
Still getting the same error...
Uncommenting these lines from the library allows me to run the command without error:
def _unflatten_asserts(flat_dict, separator):
assert isinstance(flat_dict, dict), "un_flatten requires a dictionary input"
assert isinstance(separator, str), "separator must be a string"
# assert all((not isinstance(value, Iterable) or isinstance(value, str)
# for value in flat_dict.values())), "provided dictionary is not flat"
from flatten.
Is this a unicode
and Python 2 issue? Looks like it to me. My guess would be that people who don't experience this issue are using Python 3....
e.g. on python 2.7
>>> config = {u'mfa': u'off', u'datadog.apm_config.enabled': u'true'}
>>> unflatten(config)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/flatten_json.py", line 79, in unflatten
_unflatten_asserts(flat_dict, separator)
File "/usr/local/lib/python2.7/site-packages/flatten_json.py", line 68, in _unflatten_asserts
for value in flat_dict.values())), "provided dictionary is not flat"
AssertionError: provided dictionary is not flat
>>> config['mfa']
u'off'
>>> import json
>>> json.dumps(config, indent=2)
'{\n "mfa": "off", \n "datadog.apm_config.enabled": "true"\n}'
>>> print json.dumps(config, indent=2)
{
"mfa": "off",
"datadog.apm_config.enabled": "true"
}
a workaround in my case is to cast the keys and values to strings (they're both always strings in my scenario) and then the assertion passes:
>>> config_as_str = { str(k): str(v) for k, v in config.iteritems() }
>>> config_as_str
{'mfa': 'off', 'datadog.apm_config.enabled': 'true'}
>>> unflatten(config_as_str, separator='.')
{'mfa': 'off', 'datadog': {'apm_config': {'enabled': 'true'}}}
from flatten.
Related Issues (20)
- More complex flattening? HOT 2
- ModuleNotFoundError for v0.1.8 HOT 11
- The util namespace HOT 4
- Still maintained? HOT 1
- flatten_preserve_lists returns a list instead of dict HOT 1
- flatten_preserve_lists is failed to flatten json data which includes an array with more than 10 rows HOT 1
- Error if a key is substring of another key HOT 1
- flatten_preserve_lists is failed to flatten data which has array in array
- Exploding non-nested lists rather than unpacking into separate columns
- Two different install instructions on PyPI HOT 2
- flatten option for root keys to ignore keeps some data from the root keys
- add type hints or stub file
- Several issues with flatten_preserve_lists
- Issue with unflatten
- Unflat and flat with list format a[0] instead of a.0
- Order preserving
- Wheel on pypi? HOT 1
- True Flattening
- Handling of Escaped Double Quotes
- The issue with the performance of unflattening process
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 flatten.