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 Provider should not flatten structure

See original GitHub issue

hi, I’m playing around with cfg4j and as we’re using JSON in our current setup I’d like to continue using it. However, much of the point of using json is lost if you can’t use arrays and objects (and arrays of objects) - particularly when the flattening produces strange results - e.g. "key": [{"innerKey": "value"}] fattens to just “key”: “value”

is there a particular reason why structures are flattened? The consumer of the configuration can be expected to know about the general structure of the configuration, no?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
erikwiborgcommented, May 13, 2016

sure, this is the one i’ve been using:

{
"moduleName": "name",
"seeds": ["one", "two", "three"],
"databases": [
  {
    "host": "localhost", 
    "port": 27017    
  }]
} 

thanks!

0reactions
kofrasacommented, Jul 26, 2016

You could enforce a convention in a java properties file to represent arrays or objects. The example above can be written as

moduleName=name
seeds.$0=one
seeds.$1=two
seeds.$2=three
databases.$0.host=localhost
databases.$0.port=27017

Am prefixing the number with $ to safe guard against user input that make use of numeric keys. You can also provide a Cf4gProperties class which extends Properties to facilitates retrieving the nested values.

cf4gProps.getCfgProperty("databases", 0, "host"); // return value for "database.$0.host"
cf4gProps.getProperty("database.$0.host"); // equivalent to above
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why and when do we need to flatten JSON objects?
In all cases where the JSON represents an object structure that I've combined manually, I expect it not to change. So flattening something ......
Read more >
Flattening a JSON Object So It's Queryable Using Rockset
You will often need to flatten a JSON object so you can query it. In this post, we'll show how to do so...
Read more >
Data Flattening and Data Unflattening | Firebolt Gloassary
Data flattening usually refers to the act of flattening semi-structured data, such as name-value pairs in JSON, into separate columns where the name...
Read more >
Flatten To JSON Function - NI - National Instruments
JSON string is the flattened data encoded in UTF-8. UTF-8 encoded strings may not display correctly in LabVIEW controls.
Read more >
flatten - Functions - Configuration Language | Terraform
Indirectly-nested lists, such as those in maps, are not flattened. ... we must first flatten the structure to produce a collection where each...
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