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.

Converting back to JSON

See original GitHub issue

Is it possible to convert back to JSON from form data in node?

My use case is that I would like to assert the form data I have sent has been mapped correctly

I.E the flow is

JSON data > Mapped to correct structure > Form data created > Payload sent

This would then be used to perform tests like the code below demonstrate ( Nock will pass my the API calls payload automatically making these kind of tests very convenient )

expect(formPayload.products.length).toEqual(originalJSON.items.length)

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
andrewmclagancommented, Nov 14, 2019

If this library implemented the official FormData API specifications we would be able to iterate over instances and return key value pairs.

1reaction
TomYeomancommented, Jul 16, 2019

@alexindigo thanks for the information - the issue is I don’t have scope to the stream within my tests I just have a string which looks like the following

12312321
----------------------------584171990226462722659061
Content-Disposition: form-data; name="city"

----------------------------584171990226462722659061
Content-Disposition: form-data; name="zipcode"

10010
----------------------------584171990226462722659061
Content-Disposition: form-data; name="address"

Test
----------------------------584171990226462722659061
Content-Disposition: form-data; name="streetNumber"

55

Do you know if I can convert this without writing some hacky parser myself?

At the minute i’m just doing some nasty

	expect(body).toMatch('storeOid');
	expect(body).toMatch(config.parameters.storeOid);

	expect(body).toMatch('externalStoreId');
	expect(body).toMatch(order.location.id.toString());

type assertions whereas i’d much rather be targeting specific nodes

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reverse of JSON.stringify? - Stack Overflow
I read the OP as saying "I converted a javascript object to a JSON string, and now I want to convert it back...
Read more >
Converting Javascript Objects into Strings with JSON.stringify()
JSON stringification is the process of converting a Javascript object to a flat JSON string that can be used inside a program.
Read more >
Convert an Object to JSON String using JavaScript | bobbyhadz
Use the `JSON.stringify()` method to convert an object to a JSON string, ... The method takes a value, converts it to a JSON...
Read more >
JSON methods, toJSON - The Modern JavaScript Tutorial
JSON.stringify to convert objects into JSON. JSON.parse to convert JSON back into an object. For instance, here we JSON.stringify a student:.
Read more >
JSON.stringify() - JavaScript - MDN Web Docs
The JSON.stringify() method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or ...
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