scieee AI-readable full text Open interactive document viewer

DataGen: JSON/XML Dataset Generator

Santos, Filipa Alves dos; Cardoso, Hugo André Coelho; Costa, João da Cunha e; Carvalho, Válter Ferreira Picas; Ramalho, José Carlos

Abstract

In this document, it is described the steps towards DataGen’s implementation. DataGen is a versatile and powerful tool that allows for quick prototyping and testing of software applications, since currently too few solutions offer both the complexity and scalability necessary to generate adequate datasets in order to feed a data API or a more complex APP, enabling their testing with appropriate data volume and complexity. DataGen’s core is a Domain Specific Language (DSL) that was created to specify datasets. This language suffered several updates: repeating fields (with no limit), fuzzy fields (statistically generated), lists, high order functions over lists, custom made transformation functions. The final result is a diversified algebra that allows the generation of very complex datasets coping with very convoluted requirements. Throughout the paper, several examples of the possibilities will be given. After generating a dataset, DataGen gives the user the possibility to generate a RESTFul data API with it, creating a running prototype. This solution has already been used in real life cases, described with more detail throughout the paper, in which it was able to create the intended datasets successfully. These allowed the application’s performance to be tested and for the right adjustments to be made. The tool is currently being deployed for general use.

Full text

DataGen: JSON/XML Dataset Generator1 Filipa Alves dos Santos2 University of Minho, Portugal3 [email protected]4 Hugo André Coelho Cardoso5 University of Minho, Portugal6 [email protected]7 João da Cunha e Costa8 University of Minho, Portugal9 [email protected]10 Válter Ferreira Picas Carvalho11 University of Minho, Portugal12 [email protected]13 José Carlos Ramalho14 Department of Informatics, University of Minho, Portugal15 [email protected]16 Abstract 17 In this document, it is described the steps towards DataGen’s implementation.18 DataGen is a versatile and powerful tool that allows for quick prototyping and testing of software 19 applications, since currently too few solutions offer both the complexity and scalability necessary 20 to generate adequate datasets in order to feed a data API or a more complex APP, enabling their 21 testing with appropriate data volume and complexity.22 DataGen’s core is a Domain Specific Language (DSL) that was created to specify datasets. 23 This language suffered several updates: repeating fields (with no limit), fuzzy fields (statistically 24 generated), lists, high order functions over lists, custom made transformation functions. The final 25 result is a diversified algebra that allows the generation of very complex datasets coping with very 26 convoluted requirements. Throughout the paper, several examples of the possibilities will be given. 27 After generating a dataset, DataGen gives the user the possibility to generate a RESTFul data 28 API with it, creating a running prototype.29 This solution has already been used in real life cases, described with more detail throughout 30 the paper, in which it was able to create the intended datasets successfully. These allowed the 31 application’s performance to be tested and for the right adjustments to be made.32 The tool is currently being deployed for general use.33 2012 ACM Subject Classification Software and its engineering → Domain specific languages; Theory 34 of computation → Grammars and context-free languages; Information systems → Open source 35 software36 Keywords and phrases JSON, XML, Data Generation, Open Source, REST API, Strapi, JavaScript, 37 Node.js, Vue.js, Scalability, Fault Tolerance, Dataset, DSL, PEG.js, MongoDB38 Digital Object Identifier 10.4230/OASIcs.SLATE.2021.539 1 Introduction40 Every application and software developed should be thoroughly tested before release, in order 41 to determine the system’s ability to withstand realistic amounts of data and traffic, and 42 that implies the usage of representative datasets that fit its use cases. The creation of said 43 datasets is a laborious and drawn out process, as it implies firstly generating the test data 44 in some way, in a file format compatible with the system. As it stands, there are currently 45 ©F. Santos, H. Cardoso, J. Costa, V. Carvalho, J.C. Ramalho; licensed under Creative Commons License CC-BY 10th Symposium on Languages, Applications and Technologies (SLATE 2021). Editors: Ricardo Queirós, Mário Pinto, Alberto Simões, Filipe Portela, and Maria João Pereira; Article No. 5; pp. 5:1–5:15 OpenAccess Series in Informatics Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl Publishing, Germany 5:2 DataGen no efficient, intuitive and scalable tools to do this and so, developers often end up having 46 to create test records either by hand, which is incredibly inefficient and time-consuming, or 47 by using existing tools with some clever tactics to manage their shortcomings. As a matter 48 of fact, many projects are not able to progress to the development stage due to the lack of 49 adequate and sufficient data [3].50 Even with a reliable generation tool, the user might want to have control over the data in 51 the resulting records, being able to observe and manipulate it freely, through CRUD requests, 52 and adapting it however they want. Though there are products capable of doing this - for 53 example the package json-server, which creates a full fake REST API -, its usage entails the 54 user manually starting the application every time they want to edit the dataset’s contents 55 and ensuring the data’s format is compliant with the software they’re using, which ends up 56 requiring a lot of extra effort and setup on the user’s side.57 As such, the team came up with the idea of coupling the generation process and the 58 REST API, in a way that allows the user to automatically generate data compatible with an 59 integrated RESTful API - for which the software Strapi was chosen, as will be explained in 60 more detail in section 3.4 -, allowing the user to load the records into an API server and 61 perform CRUD operations over it, either through the user interface or via HTTP requests.62 This paper will cover the development of the resulting application, DataGen - a more 63 versatile and powerful tool for data generation, according to the user’s specifications, and 64 subsequent handling -, seeking to explain the decisions that were taken for its architecture, 65 as well as all the implemented functionalities.66 2 Related Work67 User privacy concerns [ 13 ] have been a major topic of discussion over the last decades, which 68 lead to the creation of strict regulations regarding the way sensitive data should be handled, 69 such as the EU’s General Directive on Data Protection GDPR [ 2 ]. These regulations keep 70 entities from disclosing private and sensitive information, which in turn hurts new growing 71 ideas and projects that would require access to similar data. As it stands, not only is the 72 lack of available data a big problem in this context, as are the data sharing agreements 73 themselves, as their ratification tends to take, on average, a year and a half [ 10 ], which proves 74 to be fatal for many small and upcoming companies.75 To circumvent these concerns, organisations have been increasingly adopting synthetic 76 data generation [ 16 ], an approach that was originally suggested by Rubin in 1993 [ 1 ] in 77 order to create realistic data from existing models without compromising user privacy. The 78 prospect of being able to create viable information that does not relate to actual individuals is 79 a very enticing solution for the privacy conundrum. If perfected, it could potentially provide 80 the capacity of generating sizeable amounts of data according to any use cases, bypassing the 81 need to access real users’ information. As such, this approach has been increasingly adopted 82 and put to the test, in order to measure its efficiency with real-life cases [5, 14, 18].83 Dataset generation has become a requisite in many development projets. However, the 84 majority of developed tools produce datasets for specific contexts like intrusion detection 85 systems in IoT [ 4 ], crops and weed detection [ 6 ], vehicular social networks based on floating 86 car data [ 12 ], 5G channel and context metrics [ 17 ], GitHub projects [ 9 ], to cite a few. Many 87 others exist in different contexts like medicine, bioinformatics, weather forecasts, color 88 constancy, market analysis, etc.89 Most of the researched tools are domain specific. The team’s goal is to create a generic 90 tool but powerful enough to generate datasets for several and different contexts and with 91 F. Santos, H. Cardoso, J. Costa, V. Carvalho, J.C. Ramalho 5:3 many levels of complexity. There are some tools available, many online, but they cover the 92 generation of simple datasets, many times flat datasets.93 The main source of inspiration for this project was an already existing web application 94 called "JSON Generator", developed by Vazha Omanashvili [ 11 ], as it is the most interesting 95 dataset generation tool that was found. It features a DSL (Domain Specific Language) that’s 96 parsed and converted into a JSON dataset, allowing the user to generate an array of objects 97 that follow some predefined structure, specified in the DSL.98 In terms of utility, it is a very powerful tool that can generate very complex data structures 99 for any application with relatively little effort. However, it had some shortcomings which 100 initially inspired the team to develop an alternative solution that attempts to address them. 101 Specifically, these shortcomings are:102 1. Limited size for the ’repeat’ statement (100 total). Arguably, the size of the dataset itself 103 is one of the most important features to take into account. For applications on a larger 104 scale, having a small amount of array elements does not allow for more realistic tests, 105 as very few, if any, that are developed in a production environment use as little as 100 106 entries created by the aforementioned directive.107 2. It only generates JSON. Despite being one of the most popular file formats, there are 108 many others that could be useful to the user as they might want the data to be in a 109 different format for their application without converting the JSON themselves, such as 110 XML (another open text format [ 19 ]). This allows for further flexibility and expands the 111 possible use cases that it provides.112 3. Does not generate a RESTful API for the dataset. Many users may optionally want their 113 newly generated dataset hosted and exposed by a RESTful API for direct usage in their 114 web applications, or to download a custom one created specifically for their dataset for 115 later deployment on a platform of their choosing.116 4. Does not take into account fuzzy generation. Some elements of a dataset may not be 117 deterministic and are represented by probabilities. For example, there may a field that 118 exists only if another property has a specific value and the application should be able to 119 take that into account.120 5. It does not have much data available. For instance, the user might want to use names 121 from a list of famous people for their dataset, as it allows for a more realistic generation 122 and consistency, which this tool currently does not provide.123 6. It is not multilingual. The data that this application uses is only available in English, it 124 would be more user-friendly to give them the choice to use their preferred language for 125 the dataset instead of forcing it to just one.126 7. Does not take into account integration on applications. The generation and download of 127 a dataset requires the consumer to use the website’s interface - this is not ideal as many 128 applications may want to use HTTP requests to automate this process for internal usage. 129 8. Does not support functional programming features. Functions such as ’map’, ’reduce’ and 130 ’filter’ that are staple in the functional paradigm due to their simplicity and effectiveness 131 are not present in this application. This would allow the user to chain statements and 132 transform fields to the result they want, granting the application the ability to deal with 133 more complex use cases.134 With clear goals and an initial application to take inspiration from, the team proceeded 135 to the development stage by deciding on its architecture (i.e. programming languages, 136 frameworks, external tools, etc), which will be explained in the following sections.137 SLATE 2021 5:4 DataGen 3 DataGen Development138 Building the application from the ground up requires a divide and conquer approach, since139 having a monolithic single server architecture will lead to a less stable user experience, due 140 to the lack of scalability.141 Having the application compartmentalized in multiple servers, each with their specific 142 function, allows for a much more sensible and balanced architecture since it leaves room for 143 the possibility of individually upgrading each of them, leading to a much higher scalability 144 and fault tolerance, as the failure of one component does not compromise the functionality 145 of the entire application, allowing for quicker and easier routine maintenance.146 The following subsections will explain how the current architecture was achieved and the 147 technological decisions behind each of the components.148 3.1 Architecture149 The picture below shows the general scope of the architecture, albeit simplified. This 150 architecture allows for major upgrades, such as load balancers on both the back and front-end 151 since they are both stateless (the JWT approach allows the servers to not maintain sessions 152 with each user’s state) and using MongoDB as a distributed database - sharded cluster.153 Figure 1 Current architecture of DataGen 3.2 Front-End154 The first component needed for the application is the front-end server, which is responsible 155 for building and showing the website’s interface to the user, making it the entry point to the 156 application and its scripted behaviour.157 3.2.1 Grammar158 The application uses a PEG.js grammar-based parser [ 8 ] [ 15 ] to process the user’s input 159 and generate the intended dataset. The aforementioned grammar defines a domain-specific 160 language (DSL), with JSON-like syntax, providing many features that allow for the generation 161 of complex and diverse datasets. These features include relational and logic capabilities, 162 F. Santos, H. Cardoso, J. Costa, V. Carvalho, J.C. Ramalho 5:5 providing means for the datasets to satisfy several forms of constraints - which push towards 163 the use of some declarative framework for this specification -, as well as functional capabilities, 164 allowing for easier management and processing of certain properties of the datasets.165 The first and most fundamental of said features is the JSON-similar syntax - the user 166 can specify key-value properties, where the value may take any of the basic JSON types and 167 data structures, from integers to objects and arrays. The user may also nest these to create 168 a structure with any depth they may want.169 name: { first: ["John", "William"], last: "Doe" }, age: 21 To specify the size of the dataset, or a nested array, there is the repeat statement, where 170 the user indicates the structure that they want replicated (which may range from a primitive 171 JSON type to a complex object), as well as the number of copies, or range of numbers.172 names: [ ’repeat(150,200)’: { first: ’{{firstName()}}’, last: ’{{surname()}}’ } ] They may also specify as many collections as they want in a single model (collections are 173 the key-value properties on the uppermost level of the model) and the application will return 174 the resulting dataset in json-server syntax - an object with a property for each collection. 175 During the parsing of the input, the application recursively builds both the final dataset 176 and the Strapi model for the specified structure, concurrently, in order to allow for posterior 177 integration in a RESTful API.178 { names: [ ’repeat(10)’: ’{{fullName()}}’ ], animals: [ ’repeat(20)’: ’{{animal()}}’ ] } To define the value of a property, the user may also use interpolation. To access an 179 interpolation function, it must be encased in double curly braces. There are two types of 180 interpolation functions:181 functions that generate spontaneous values during execution, according to the user’s 182 instructions - for example, there is a random integer generation function where the user 183 must provide a range of values for the intended result:184 id: ’{{objectId()}}’, int: ’{{integer(50,100)}}’, random: ’{{random(23, "hello", [1,2,3], true)}}’ SLATE 2021 5:6 DataGen functions that return random values from a group of datasets incorporated in the applica- 185 tion behind an API, where each dataset has information of a given category, for example 186 names and political parties.187 name: ’{{fullName()}}’, party: ’{{political_party()}}’ These interpolation functions may also be interwoven together and with normal strings to 188 generate more structured strings, such as addresses. Some of them take arguments, in which 189 case the user can either manually introduce the value or reference another property defined 190 above, through a variable this, allowing them to establish relations between properties.191 parish: ’{{pt_parish()}}’, district: ’{{pt_district("parish", this.parish)}}’, address: ’St. {{fullName()}}, {{pt_city("district", this.district)}}’ In regard to the API of datasets, the team did an extensive search for useful datasets, 192 used the well-structured ones it found and salvaged whatever information it could from 193 others that were maybe less organized, processing this information to remove errors and 194 normalize its content, before joining it with other data of the same topic to create bigger, 195 more complete datasets for the user to use.196 The team also created some original datasets by hand, for topics deemed appropriate, 197 and manually introduced bilingual support, for both portuguese and english, in all datasets 198 made available in the application, in order to let the user choose whichever language suits 199 best their goal. To indicate their language of choice, the user’s model must start with the 200 following syntax:201 <!LANGUAGE pt> or <!LANGUAGE en> Currently, DataGen has support datasets of all the following categories: actors, animals, 202 brands, buzzwords, capitals, cities, car brands, continents, countries, cultural landmarks, 203 governmental entities, hackers, job titles, months, musicians, names, nationalities, political 204 parties, portuguese businessmen, portuguese districts, cities, counties and parishes, por- 205 tuguese public entities, portuguese politicians, portuguese public figures, portuguese top 206 100 celebrities, religions, soccer clubs, soccer players, sports, top 100 celebrities, weekdays, 207 writers.208 The grammar also makes available a feature named unique() , to which the user may 209 provide an interpolation function, or a string interpolated with such a function, as an 210 argument. unique guarantees that the interpolation functions on which it is applied always 211 return unique values. This is especially relevant when it comes to interpolation functions 212 that fetch random data from the support datasets inside a repeat statement, as there is no 213 guarantee that there won’t be duplicates among the fetched records and the user might not 214 want that.215 As such, unique only has any effect when applied on dataset interpolation functions or 216 with random (which can be observed in one of the examples from last page). As long as 217 it’s one of those (possibly interpolated with normal strings) and there are sufficient distinct 218 entries for the entire repeat statement, this tool guarantees that all objects in the resulting 219 dataset will have a different value in the property in question. If the user uses a string 220 F. Santos, H. Cardoso, J. Costa, V. Carvalho, J.C. Ramalho 5:7 with more than one interpolation function, there is also no effect - there may be repeated 221 combinations in the end.222 Below are two examples: the first one depicts the correct usage of the unique feature; 223 the second shows instances of a wrong approach (not enough distinct values for the repeat 224 statement; not a dataset interpolation function or the random function; more than one 225 interpolation function) that will either not work or not assure any mutually exclusive 226 guarantee for the resulting values:227 [ ’repeat(6)’: { continent: unique(’{{continent()}}’), country: unique(’Country: {{country()}}’), random: unique(’{{random(1,2,3,4,5,6)}}’) } ] [ ’repeat(10)’: { continent: unique(’{{continent()}}’), int: unique(’{{integer(5,20)}}’), name: unique(’{{firstName()}} {{surname()}}’) } ] Back to the properties of the model, the user may also use JavaScript functions to define 228 their value. There are two types of functions: signed functions, where the name of the 229 method corresponds to the key of the property, while the result of the body of the function 230 translates to its value, and anonymous arrow functions, which are used to indicate solely the 231 value of a property (the key needs to be precised separately beforehand).232 name: "Oliver", email(gen) { var i = gen.integer(1,30); return ‘${this.name}.${gen.surname()}${i}@gmail.com‘.toLowerCase(); }, probability: gen => { return Math.random() * 100; } Inside these functions, the user is free to write JavaScript code that will be later executed to 233 determine the value of the property. This way, more complex algorithms may be incorporated 234 into the construction logic of the dataset, allowing for a more nuanced and versatile generation 235 tool. Given that the user has access to the whole Javascript syntax, they may make use 236 of relational and logical operators to elaborate conditions on the intended data, as well as 237 functional methods (for example "map" or "filter", which Javascript implements).238 Inside these blocks of code, the user has full access to any property declared above in 239 the DSL model, through the variable this , as well as any interpolation function available in 240 the parser, through a gen variable - whenever using a function, the user must declare this 241 argument in its signature, which they may then use inside to run said interpolation functions. 242 All of this can be observed in the example above.243 The grammar also allows fuzzy generation of properties, i.e. constraining the existence of 244 certain properties based on logical conditions or probabilities. As of now, the grammar has 245 four different tools for this purpose:246 SLATE 2021 5:8 DataGen missing / having statements - as an argument, they receive the probability of the prop- 247 erties inside (not) existing in the final dataset; this probability is calculated for each 248 element, originating a dataset where some elements have said properties and others don’t: 249 missing(50) { prop1: 1, prop2: 2 }, having(80) { prop3: 3 } if... else if... else statements - these work just as in any programming language: the 250 user can use relational operators and other conditional statements to create conditions 251 and string multiple of them together with the help of logical operators. The final object 252 will have the properties specified in the first condition that evaluates to true (or eventually 253 none of them, if all conditions prove to be false). In these conditions, similar to the 254 functions, the user has unrestricted access to all properties declared above in the DSL 255 model, as well as the interpolation functions, which gives them the ability to causally 256 relate different properties:257 type: ’{{random("A","B","C")}}’, if (this.type == "A") { A: "type is A" } else if (this.type == "B") { B: "type is B" } else { C: "type is C" } the or statement - the grammar makes available this logical operator for quick prototyping 258 of mutually exclusive properties, where only one will be selected for each object (note 259 that it doesn’t make sense to create an and statement, since that translates to simply 260 listing the wanted properties normally in the DSL model):261 or() { prop1: 1, prop2: 2, prop3: 3 } the at_least statement - inside this, the user writes a set of properties and gives the 262 statement an integer argument specifying the minimum number of those properties that 263 must be present in the final object. The parser selects that number of properties randomly 264 from the given set:265 at_least(2) { prop1: 1, prop2: 2, prop3: 3 } Finally, the grammar also provides an implementation of the fundamental functional 266 programming features - map , filter and reduce . The user may chain together one or several 267 of these functions with an array value (from any of the various array-creating features made 268 F. Santos, H. Cardoso, J. Costa, V. Carvalho, J.C. Ramalho 5:9 available). Shorthand syntax is not allowed, so curly braces must always be opened for 269 the code block. Aside from that, these features work exactly like the native Javascript 270 implementations: the user may either declare the function inside or use anonymous syntax 271 for the variables; they may declare only the current value or any of the additional, albeit 272 less commonly used, variables. Examples of several possible usages of these features can be 273 observed below:274 map: range(5).map(value => { return value+1 }), filter: [0,1,2].filter(function(value, index) {return [0,1,2][index]>0}), reduce: range(5).reduce((accum, value, index, array) => { return accum + array[index] }), combined: range(5).map((value) => { return value+3 }) .filter(x => { return x >= 5}) .map(x => { return x*2 }).reduce((a,c) => {return a+c}) 3.2.2 Interoperability275 After processing the model, the parser generates an intermediary data structure with the 276 final dataset, which can then be translated to either JSON or XML, according to the user’s 277 preference. The parser also generates another data structure with the corresponding Strapi 278 model, for possible later integration in its RESTful API.279 Note that the application’s purpose is to create datasets according to the user’s instructions, 280 in either JSON or XML. Although the model specification may involve Javascript code, under 281 the form of functions or conditions, as explained in the previous subsection, this does not 282 correlate to the target application whatsoever. DataGen merely generates test datasets - it283 can be used for any kind of application that accepts data in JSON/XML format, whether it 284 be an application written in Javascript, Python, C++ or some other language.285 3.2.3 Client-Side Generation286 This project was developed with the intent of being a web application, more specifically a 287 website with user-friendly features. A server-sided approach would imply parsing the DSL 288 models on the back-end server, which wouldn’t be sensible as the created PEG.js parser 289 doesn’t require access to any private services (i.e. databases) hidden by the back-end itself.290 Therefore, a client-sided approach makes the most sense for this application in particular, 291 freeing resources (mainly the CPU and memory modules) from the back-end server and 292 shifting the computation of the generated dataset to the client in their browser, using the 293 back-end as an API server.294 There are many frameworks aimed at client-sided browser experiences, however, it was 295 decided that Vue.js would be the most adequate for this application. It allows for reactive two- 296 way data binding - connection between model data updates and the view (UI) which creates 297 a more user-friendly experience, since it shows changes on the DOM as they occur, instead 298 of forcing a reload on the page (as in the traditional served-sided approach). Other reasons 299 such as flexibility - on the components’ styling and scripted behaviour - and performance 300 - it’s more efficient than React and Angular - were also a deciding factor on picking this 301 specific framework.302 After deciding which framework to use, the team started developing the interface itself, 303 which currently has the following features:304 SLATE 2021